#include "mainwindow.h"
//#include "ui_mainwindow.h"
#include "iconhelper.h"
#include "myhelper.h"
#include <QSignalMapper>
#include <QWSInputMethod>
#include <QWSServer>
#include <QPalette>
#include <cmath>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//#include <sys/ioctl.h>
#include <unistd.h>
#define PI 3.1415927
#define X_Cnt 16	// luboDraw 的 X 轴坐标数目

extern QString etherPortName;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    // ui->setupUi(this);
    // ui->lab_Title->setText(tr("电子式互感器校验仪"));
    loadPortConfig();

    makeMainWidget();

    this->move(0,0);

    //setStyle(new QWindowsStyle);

    // myHelper::FormInCenter(this);
    // this->InitStyle();

    setFrmLayout();

    init();

    f_Init_F_para();

//    connect(keywidget,SIGNAL(sigHideKey()),this,SLOT(clearFocusAll()));

  //  connect(udp,SIGNAL(sigUdpDataIsOK()),this,SLOT(slotUdpDataIsOK()));
    connect(udp,SIGNAL(sigUdpDataIsOK()),this,SLOT(jsUdpWc()));
    connect(udp,SIGNAL(sigUdpDataShow()),this,SLOT(showDelayText()));
    connect(tcpServer,SIGNAL(sigTcpOrder(int)),this,SLOT(slotTcpProcess(int)));
    connect(tcpServer,SIGNAL(sigTcpStause(int)),this,SLOT(slotTcpInfo(int)));
//    connect(cappacket,SIGNAL(sigJswc()),this,SLOT(jsWc()));
    connect(cappacket,SIGNAL(sigCyOver()),this,SLOT(settempbuff()));
    connect(cappacket,SIGNAL(sigFind(QString,QString,QString,int,int)),this,SLOT(addList(QString,QString,QString,int,int)));

    connect(this,SIGNAL(sigTestEnd()),this,SLOT(slotTestEnd()));
    connect(this,SIGNAL(sigSyncSet(int)),this,SLOT(slotSyncSet(int)));

    connect(timer, SIGNAL(timeout()), this, SLOT(flushBuff()));
    connect(captimer, SIGNAL(timeout()), this, SLOT(NetTest()));
    connect(showInfoTimer,SIGNAL(timeout()), this, SLOT(hideInfo()));
    connect(showAllTimer,SIGNAL(timeout()),this,SLOT(startAll()));
    connect(fdjTimer,SIGNAL(timeout()),this,SLOT(fdjTimerOut()));
    connect(udpTimer,SIGNAL(timeout()),this,SLOT(slotUdp()));
    connect(dsTimer,SIGNAL(timeout()),this,SLOT(slotDs()));
    connect(ysTimer,SIGNAL(timeout()),this,SLOT(slotYs()));
    connect(openNetTimer,SIGNAL(timeout()),this,SLOT(slotOpenNetTimer()));
    connect(delShowtimer, SIGNAL(timeout()), this, SLOT(showDelAllMsg()));
    connect(bwTimer,SIGNAL(timeout()),this,SLOT(showBwinfo()));
  //  connect(homeLabel,SIGNAL(Clicked(ClickedLabel*)),this,SLOT(paraReturn()));
 //   connect(wcsjlabel,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(wcsjPage()));
    //  connect(newTestPage->newSysPage->btnEnter,SIGNAL(clicked()),this,SLOT(sysmanager()));
    //  connect(newTestPage->rdoPT,SIGNAL(clicked()),this,SLOT(changeset()));
    //  connect(newTestPage->rdoCltd,SIGNAL(clicked()),this,SLOT(tdSelect()));
    //  connect(newTestPage->rdoAlltd,SIGNAL(clicked()),this,SLOT(tdSelect()));
    //  connect(newLuboPage->btnLubo,SIGNAL(clicked()),this,SLOT(StartLuBo()));
    //  connect(newBwjyPage->btnBwStart,SIGNAL(clicked()),this,SLOT(bwStart()));
    //  connect(newBwjyPage->btnBwStop,SIGNAL(clicked()),this,SLOT(bwStop()));

    //  connect(newSysPage->btnSysOk,SIGNAL(clicked()),this,SLOT(sysOK()));
    //  connect(newSysPage->btnSysCancel,SIGNAL(clicked()),this,SLOT(sysCancel()));
    //
    //  connect(newWcPage->btnDel,SIGNAL(clicked()),this,SLOT(delWcdata()));

    connect(newTestPage,SIGNAL(sigList()),this,SLOT(slotShowList()));
    connect(newTestPage,SIGNAL(sigScl()),this,SLOT(slotShowScl()));
    connect(newTestPage->btnAll,SIGNAL(clicked()),this,SLOT(allPage()));
    connect(newTestPage->cboBzSelect,SIGNAL(currentIndexChanged(int)),this,SLOT(bzselect()));
    connect(newTestPage->cboBcSelect,SIGNAL(currentIndexChanged(int)),this,SLOT(bcselect()));
    connect(newTestPage->cboSave,SIGNAL(currentIndexChanged(int)),this,SLOT(changeSaveFlag()));
    connect(newTestPage->cboCTPT,SIGNAL(currentIndexChanged(int)),this,SLOT(changeset()));
    connect(newTestPage->cboCyfs,SIGNAL(currentIndexChanged(int)),this,SLOT(changeCyfs()));
    connect(newTestPage->btnTest,SIGNAL(clicked()),this,SLOT(slotBtnTest()));
    connect(newTestPage->btnSave,SIGNAL(clicked()),this,SLOT(saveWcdata()));
    connect(newTestPage->tabwc,SIGNAL(currentChanged(int)),this,SLOT(wcsjPage()));
    connect(newTestPage->btnFirst,SIGNAL(clicked()),this,SLOT(dataFirst()));
    connect(newTestPage->btnPrevious,SIGNAL(clicked()),this,SLOT(dataPrevious()));
    connect(newTestPage->btnNext,SIGNAL(clicked()),this,SLOT(dataNext()));
    connect(newTestPage->btnLast,SIGNAL(clicked()),this,SLOT(dataLast()));
    connect(newTestPage->btnDel,SIGNAL(clicked()),this,SLOT(showDelFrm()));
    connect(newTestPage->btnDel,SIGNAL(pressed()),this,SLOT(startTimer()));
    connect(newTestPage->btnDel,SIGNAL(released()),this,SLOT(stopTimer()));
    connect(newTestPage->btnFind,SIGNAL(clicked()),this,SLOT(dataFind()));

    connect(newAddPage->tabInfo,SIGNAL(clicked(QModelIndex)),this,SLOT(slotShowMenu(QModelIndex)));

    connect(newLuboPage->labColor1,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor2,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor3,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor4,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor5,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor6,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor7,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor8,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor9,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor10,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor11,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->labColor12,SIGNAL(Clicked(ClickedLabel*)), this, SLOT(changeys(ClickedLabel*)));
    connect(newLuboPage->rdoAll,SIGNAL(clicked()),this,SLOT(luboSelect()));
    connect(newLuboPage->rdoOne,SIGNAL(clicked()),this,SLOT(luboSelect()));
    connect(newLuboPage->chkSelectAll,SIGNAL(clicked(bool)),this,SLOT(selectTd(bool)));
    connect(newLuboPage->scrllCurve,SIGNAL(valueChanged(int)),this,SLOT(scrllCurveScroll()));
    connect(newLuboPage->tSlider,SIGNAL(valueChanged(int)),this,SLOT(tTest()));
    connect(newLuboPage->btnLuboData,SIGNAL(clicked()),this,SLOT(slotLuboData()));

    connect(newSclPage->btnOK,SIGNAL(clicked()),this,SLOT(setMac()));
    connect(newSclPage->tabScl,SIGNAL(clicked(QModelIndex)),this,SLOT(addTdh()));

    connect(newSysPage->btnEnter,SIGNAL(clicked()),this,SLOT(sysmanager()));
    connect(newSysPage->tabWidget,SIGNAL(currentChanged(int)),this,SLOT(tabchanged()));
    connect(newSysPage->tabCsbc,SIGNAL(clicked(QModelIndex)),this,SLOT(showEdit(QModelIndex)));
    connect(newSysPage->tabSys,SIGNAL(currentChanged(int)),this,SLOT(tabSysChanged()));
    connect(newSysPage->btnBc,SIGNAL(clicked()),this,SLOT(saveWcbc()));
    connect(newSysPage->btnSysSave,SIGNAL(clicked()),this,SLOT(saveWcbc()));
    connect(newSysPage->cboBzbc,SIGNAL(currentIndexChanged(int)),this,SLOT(showBcdata()));
    connect(newSysPage->btnSystoUpdate,SIGNAL(clicked()),this,SLOT(toUpdate()));

    connect(newBwjyPage->cboXieboNum,SIGNAL(currentIndexChanged(int)),this,SLOT(showXiebonum()));
    connect(newBwjyPage->tabWidget,SIGNAL(currentChanged(int)),this,SLOT(bwStop()));

    connect(newAllPage->btnNext,SIGNAL(clicked()),this,SLOT(NextPage()));
    connect(newAllPage->btnPre,SIGNAL(clicked()),this,SLOT(PrePage()));

    //LM 非同步测量
    connect(newTestPage->f_wcPage->btnTest,SIGNAL(clicked()),this,SLOT(slotBtnTest()));

    connect(newTestPage->f_wcPage,SIGNAL(f_sigList()),this,SLOT(f_slotShowList()));
     connect(newTestPage->f_wcPage,SIGNAL(f_sigScl()),this,SLOT(f_slotShowScl()));
    //connect(newTestPage->f_wcPage->btnAll,SIGNAL(clicked()),this,SLOT(allPage()));
    connect(newTestPage->f_wcPage->cboBzSelect,SIGNAL(currentIndexChanged(int)),this,SLOT(f_bzselect()));
    connect(newTestPage->f_wcPage->cboBcSelect,SIGNAL(currentIndexChanged(int)),this,SLOT(f_bcselect()));
    connect(newTestPage->f_wcPage->cboSave,SIGNAL(currentIndexChanged(int)),this,SLOT(f_changeSaveFlag()));
    connect(newTestPage->f_wcPage->cboCTPT,SIGNAL(currentIndexChanged(int)),this,SLOT(f_changeset()));
    connect(newTestPage->f_wcPage->cboCyfs,SIGNAL(currentIndexChanged(int)),this,SLOT(f_changeCyfs()));
    connect(newTestPage->f_wcPage->btnSave,SIGNAL(clicked()),this,SLOT(f_saveWcdata()));

    //记录MU 延时
    connect(m_clnp->recvThread,SIGNAL(receivePacket(const u_char*,int)),
            this,SLOT(parsePacket(const u_char*,int)));
    //connect(m_clnp->recvThread,SIGNAL(f_sigJswc()),this,SLOT(f_jsWc()));
    connect(m_clnp->recvThread,SIGNAL(f_sigCyOver()),this,SLOT(f_settempbuff()));
    connect(m_clnp->recvThread,SIGNAL(f_showMUYS()),this,SLOT(s_showMUYS()));

    connect(this,SIGNAL(f_sigTestEnd()),this,SLOT(f_slotTestEnd()));

    connect(fakePPS, SIGNAL(timeout()), this, SLOT(jsWc()));

    //LM 非同步测量

    packet_analyzer.start("packet_analyzer.exe");
}

MainWindow::~MainWindow()
{
    packet_analyzer.kill();

    udpOrder(0);
    udpTimer->stop();
    udp->setRead(false);
    myDB->CloseDB();
    closePWM();
//    delete ui;
}

void MainWindow::makeMainWidget()
{
    //this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint|Qt::WindowStaysOnTopHint);
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);

    QWidget *thisWidget = new QWidget(this);
    thisWidget->setFixedSize(1280, 800);

    //for title bar
    labIcon = new QLabel;
    labIcon->setFixedWidth(30);

    labTitle = new QLabel;
    labTitle->setStyleSheet("font-size: 20px;");
    labTitle->setFixedWidth(1000);
    labTitle->setText("电子式互感器校验仪");

    btnPhoto = new QPushButton;
    btnPhoto->setFixedSize(40,35);
    btnMenu = new QPushButton;
    btnMenu->setFixedSize(40,35);
    btnClose = new QPushButton;
    btnClose->setFixedSize(40,35);

    connect(btnClose, SIGNAL(clicked()),this,SLOT(on_btnMenu_Close_clicked()));
    connect(btnPhoto,SIGNAL(clicked()),this,SLOT(on_btnPhoto_clicked()));

    IconHelper::Instance()->SetIcon(btnClose, QChar(0xf00d), 15);
    IconHelper::Instance()->SetIcon(btnMenu, QChar(0xf0c9), 17);
    IconHelper::Instance()->SetIcon(labIcon, QChar(0xf015), 17);
    IconHelper::Instance()->SetIcon(btnPhoto, QChar(0xf030), 15);

    QMenu *styMenu = new QMenu();
    styMenu->setStyleSheet("font-size:20px;");
    QAction *blue_action = new QAction(tr("室内模式"),styMenu);
    QAction *gray_action = new QAction(tr("室外模式"),styMenu);

    styMenu->addAction(blue_action);
    styMenu->addAction(gray_action);

    btnMenu->setMenu(styMenu);
    btnMenu->setStyleSheet("QPushButton::menu-indicator{image:None;}");

    connect(blue_action,SIGNAL(triggered()),this,SLOT(slotBlack()));
    connect(gray_action,SIGNAL(triggered()),this,SLOT(slotBlue()));

    QHBoxLayout *layoutTitle = new QHBoxLayout;
    layoutTitle->setContentsMargins(0,0,0,0);
    layoutTitle->addSpacing(20);
    layoutTitle->addWidget(labIcon);
    layoutTitle->addSpacing(10);
    layoutTitle->addWidget(labTitle);
    layoutTitle->addStretch(1);
    layoutTitle->addWidget(btnPhoto);
    layoutTitle->addSpacing(5);
    layoutTitle->addWidget(btnMenu);
    layoutTitle->addSpacing(5);
    layoutTitle->addWidget(btnClose);
    layoutTitle->addSpacing(10);

    QWidget *widget_title = new QWidget;
    widget_title->setFixedSize(1280, 40);
    widget_title->setLayout(layoutTitle);
    //widget_title->setStyleSheet(".QWidget{background-color: #333}");

    //for stacked pages
    pagesWidget = new QStackedWidget;
    pagesWidget->setFixedSize(1280,760);

    QVBoxLayout *horizontalLayout = new QVBoxLayout;
    horizontalLayout->setContentsMargins(0,0,0,70);
    horizontalLayout->addWidget(widget_title);
    horizontalLayout->addWidget(pagesWidget);

    thisWidget->setLayout(horizontalLayout);

    this->setCentralWidget(thisWidget);

    // set the background color
    setAutoFillBackground(true);
    QPalette p = palette();
    p.setColor(QPalette::Window,QColor(192, 192, 192));
    setPalette(p);

    //newTestPage->labBcys->setText(tr("被测:绿色"));

    dataPen.setColor(Qt::green);
    dataPen.setWidth(2);
}

void MainWindow::slotTcpInfo(int flag)
{
    if (flag>=0)
    {
        m_bIsConn=true;
        labTitle->setText(tr("电子式互感器校验仪--已联机"));
        ////
      //  QString s=QDir::currentPath()+"/pcap/2014-10-23 14:33:00.pcap";
      //  tcpServer->TcpSendFile(s);
    }
    else
    {
        m_bIsConn=false;
        labTitle->setText(tr("电子式互感器校验仪"));
    }
}

void MainWindow::slotOpenNetTimer()
{
    if (!openNetFlag)
        cappacket->StopCap(true);
    openNetTimer->stop();
}

void MainWindow:: slotBlack()
{
    myHelper::SetStyle("black");//黑色风格

    QPalette p = palette();
    p.setColor(QPalette::Window,QColor(18,29,34));
    setPalette(p);
    newTestPage->labBcys->setText(tr("被测:蓝色"));

    dataPen.setColor(Qt::blue);
    dataPen.setWidth(1);
 //   newTestPage->changeSty(0);
}
void MainWindow:: slotBlue()
{
    myHelper::SetStyle("outdoor");//蓝色风格
  //  QPalette pal;   //设置背景
  //  QPixmap pixmap(QDir::toNativeSeparators(":image/bj-blue.jpg"));
 //   pal.setBrush(QPalette::Window, QBrush(pixmap));
 //   setPalette(pal);
 //   setAutoFillBackground(true);
    QPalette p = palette();
    p.setColor(QPalette::Window,QColor(192, 192, 192));
    //p.setColor(QPalette::Window,mintcream);
    setPalette(p);
    newTestPage->labBcys->setText(tr("被测:绿色"));

    dataPen.setColor(Qt::green);
    dataPen.setWidth(2);
 //   newTestPage->changeSty(1);
}
void MainWindow:: slotGray()
{
    myHelper::SetStyle("gray");//灰色风格
    QPalette p = palette();
    p.setColor(QPalette::Window,QColor(53,53,53));
    setPalette(p);
//    newTestPage->changeSty(2);
}
void MainWindow:: slotNavy()
{
    myHelper::SetStyle("navy");//天蓝色风格
 //   QPalette pal;   //设置背景
  //  QPixmap pixmap(QDir::toNativeSeparators(":image/bj-navy.jpg"));
  //  pal.setBrush(QPalette::Window, QBrush(pixmap));
   // setPalette(pal);
    QPalette p = palette();
    p.setColor(QPalette::Window,QColor(21,87,110));
    setPalette(p);
 //   newTestPage->changeSty(3);
}

//void MainWindow::InitStyle()
//{
//    //设置窗体标题栏隐藏
//    //  this->setFixedSize(WIDTH,HEIGHT);
//    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
//    location = this->geometry();
//    max = false;
//    mousePressed = false;

//    //安装事件监听器,让标题栏识别鼠标双击
//  //  ui->lab_Title->installEventFilter(this);

//    IconHelper::Instance()->SetIcon(ui->btnMenu_Close, QChar(0xf00d), 10);
//    IconHelper::Instance()->SetIcon(ui->btnMenu, QChar(0xf0c9), 10);
//    IconHelper::Instance()->SetIcon(ui->lab_Ico, QChar(0xf015), 12);
//    IconHelper::Instance()->SetIcon(ui->btnPhoto, QChar(0xf030), 10);

//    QMenu *styMenu = new QMenu();
//    QAction *black_action = new QAction(tr("室内模式"),styMenu);
//    QAction *blue_action = new QAction(tr("室外模式"),styMenu);
//    QAction *gray_action = new QAction(tr("灰色风格"),styMenu);
//    QAction *navy_action = new QAction(tr("天蓝色风格"),styMenu);
//    styMenu->addAction(black_action);
//    styMenu->addAction(blue_action);
////    styMenu->addAction(gray_action);
////    styMenu->addAction(navy_action);
//    ui->btnMenu->setMenu(styMenu);
//    ui->btnMenu->setStyleSheet("QPushButton::menu-indicator{image:None;}");
// //   ui->btnMenu->setStyleSheet("QPushButton::item{border: 0px}");
//    connect(black_action,SIGNAL(triggered()),this,SLOT(slotBlack()));
//    connect(blue_action,SIGNAL(triggered()),this,SLOT(slotBlue()));
//    connect(gray_action,SIGNAL(triggered()),this,SLOT(slotGray()));
//    connect(navy_action,SIGNAL(triggered()),this,SLOT(slotNavy()));

//    contentsWidget = new QListWidget;
//    contentsWidget->setViewMode(QListView::IconMode);
//    contentsWidget->setIconSize(QSize(96, 84));
//    contentsWidget->setMovement(QListView::Static);
//    contentsWidget->setMaximumWidth(128);
//    contentsWidget->setSpacing(12);

//    pagesWidget = new QStackedWidget;

//    QHBoxLayout *horizontalLayout = new QHBoxLayout;
//   // horizontalLayout->addWidget(contentsWidget);
// //   horizontalLayout->addLayout(btnLayout);
//    horizontalLayout->addWidget(pagesWidget);

//    QVBoxLayout *mainLayout = new QVBoxLayout;
//    mainLayout->addLayout(horizontalLayout);
// //   mainLayout->addStretch(1);

//    ui->verticalLayout->addLayout(mainLayout);

//    setAutoFillBackground(true);
//    QPalette p = palette();
//    p.setColor(QPalette::Window,QColor(18,29,34));
//    setPalet;te(p)

//    dataPen.setColor(Qt::blue);
//    dataPen.setWidth(1);
//}

/*
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
    if (mousePressed && (e->buttons() && Qt::LeftButton) && !max) {
        this->move(e->globalPos() - mousePoint);
        e->accept();
    }
}
*/
void MainWindow::on_btnPhoto_clicked()
{
    QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());

    QString format = "png";

    QDateTime time = QDateTime::currentDateTime();

    QString str = time.toString("yyyy-MM-dd-hh-mm-ss");

    QString filename = str + ".png";

    QDir toDir= QDir::currentPath();

    if(toDir.exists("c://model-1000/screenshot"))
    {
         qDebug() << "/screenshot/ is existed!";

         toDir.setPath("c://model-1000/screenshot");
         toDir.setFilter(QDir::Files);
         toDir.setSorting(QDir::Time);

         QFileInfoList list = toDir.entryInfoList();

         int i = 0;
         for(i=0 ; i<list.size(); i++)
         {
             if(i > 50)
             {
                 QFileInfo fileInfo = list.at(i);
                 toDir.remove( fileInfo.fileName() );

                 qDebug() << "Deleted file: "<<fileInfo.fileName();
             }
         }
    }
    else
    {
         qDebug() << "mkdir screenshot";
         toDir.mkdir("c://model-1000/screenshot");
         toDir.setPath("c://model-1000/screenshot");
    }

     filename = toDir.absolutePath()+ "/" + filename;

     if (!filename.isEmpty())
     {
         originalPixmap.save(filename, format.toAscii());
         QString s=tr("截图已保存！请及时使用 U 盘下载！");
         labInfo->setText(s);
         widgetInfo->show();
         showInfoTimer->start(2000);
     }

}

void MainWindow::on_btnMenu_Close_clicked()
{
    qApp->exit();
}

void MainWindow::hideInfo()
{
    showInfoTimer->stop();
    labInfo->setText("");
    widgetInfo->hide();
    newTestPage->labInfo->setText("");
    newBwjyPage->labInfo->setText("");
    newBwjyPage->labInfoDs->setText("");
}
void MainWindow::init()
{
    sourceIsActive = false;

    fakePPS = new QTimer(this);
    fake_pps_count = 0;

    myDB=new ProjectDB();
    timer = new QTimer(this);
    captimer= new QTimer(this);
    delShowtimer=new QTimer(this);
    showInfoTimer=new QTimer(this);
    bwTimer=new QTimer(this);
    showAllTimer=new QTimer(this);
    fdjTimer=new QTimer(this);
    udpTimer=new QTimer(this);
    openNetTimer=new QTimer(this);
    cappacket=new CapPacket();
    m_clnp = new Clnp("ether proto 0x815A");//LM 非同步测量
    tDataProcess=new TotalDataProcess();
    udp=new UdpClient();
    tcpServer=new TcpServer();
    //keywidget=new keyWidget(this);
    dsTimer=new QTimer(this);
    ysTimer=new QTimer(this);

    //keywidget->setFocusPolicy(Qt::NoFocus);  //设置为无焦点
    //keywidget->setVisible(false);
    m_dblYXZ_HGQ = 0;
    m_dblYXZ_JYY = 0;
    m_dblBC = 0;			// 比差
    m_dblXW_HGQ = 0;
    m_dblXW_JYY = 0;
    m_dblJC = 0;			// 角差
    bmstart=false;
    bStart=false;
    bzorbc=0;
    m_iAvgNum=10;
    nowXh="";
    preBFD="";
    clfs=0;
    bee=false;
    pwmfd=-1;
    bDbd=false;
    isTested=false;
    memset(tempbuff,0,sizeof(tempbuff));
    //ui->frakey->setStyleSheet("background-color:#C7C1F9");
    changeData();
    f_changeData();//LM 非同步测量

    setBzBcXs();
    m_iFlag=0;
    nowtest=-1;
    openNetFlag=false;
    loadCfg();
    udpResendNum=0;
    m_bIsConn=false;
 //   openPWM();

    packet_testing = false;

    allChannelShow=0;
    memset(maxInChanel, 0x00,sizeof(maxInChanel));
}
void MainWindow::setBzBcXs()
{
    for(int i=0;i<10;i++)
    {
        bzxs[i]=1;
        bcxs[i]=1;
    }
    QString sPath=QCoreApplication::applicationDirPath();
    QString sfile=sPath +"/"+ tr("xs.txt");
    if (!QFile::exists(sfile))
    {
        return;
    }
    else
    {
        QFile file(sfile);
        if (file.open(QIODevice::ReadOnly))
        {
            QString sText=file.readAll();
            char charSplit=0X0A;
            QStringList sPoints=sText.split(charSplit);
            QString bz=sPoints.at(0);
            QString bc=sPoints.at(1);
            charSplit=';';
            QStringList sP=bz.split(charSplit);
            for(int i=0;i<sP.length();i++)
            {
                if (i>=10)
                    break;
                QString s=sP.at(i);
                bzxs[i]=s.toDouble();
            }
            QStringList sM=bc.split(charSplit);
            for(int i=0;i<sM.length();i++)
            {
                if (i>=10)
                    break;
                QString s=sM.at(i);
                bcxs[i]=s.toDouble();
            }
        }
    }
}

void MainWindow::setFrmLayout()
{
    QFont ft;
    ft.setPointSize(14);
    ft.setBold(true);
    widgetInfo=new QWidget(this);
    labInfo=new QLabel("");
    labInfo->setStyleSheet("color:#FFFF00");
    labInfo->setMinimumWidth(500);
    labInfo->setMaximumWidth(500);
    labInfo->setFont(ft);
    QHBoxLayout *tlLayout = new QHBoxLayout;
    tlLayout->addWidget(labInfo);
    widgetInfo->setLayout(tlLayout);
    widgetInfo->setGeometry(400,230,500,100);
    widgetInfo->hide();

    newTestPage=new TestPage;
    newLuboPage=new LuboPage;
    newSysPage=new SysPage;
    newWcPage=new WcPage;
    newBwjyPage=new BwjyPage;
    newAllPage=new AllPage;
    newSclPage=new SclPage(this);
    newSclPage->setVisible(false);
    pagesWidget->addWidget(newTestPage);    //0
    pagesWidget->addWidget(newAllPage);    //1

    newAddPage=new AddPage;
    newTestPage->tabwc->addTab(newAddPage,tr("加量输出"));
   // newLuboaPage=new LuboaPage;
    newTestPage->tabwc->addTab(newLuboPage,tr("录波分析"));
 //   newMuPage=new BwjyPage;
    newTestPage->tabwc->addTab(newBwjyPage,tr("MU检测"));
  //  newExPage=new ExPage;
    newTestPage->tabwc->addTab(newSysPage,tr("系统设置"));

    //f_Init_F_para();

    newTestPage->txtBzXdy->installEventFilter(this);     //在窗体上为lineEdit安装过滤器
    newTestPage->txtBcXdy->installEventFilter(this);
    newTestPage->txtEdyc->installEventFilter(this);


    newTestPage->txtTestNum->installEventFilter(this);
  //  newTestPage->txtYanshi->installEventFilter(this);
    newSysPage->txtMima->installEventFilter(this);
    newSysPage->txtBcbc->installEventFilter(this);
    newSysPage->txtJcbc->installEventFilter(this);

  //  newTestPage->txtXbYxz->installEventFilter(this);
  //  newLuboPage->widget->installEventFilter(this);
    newLuboPage->txtLuboTime->installEventFilter(this);
    newSysPage->txtBCCYSL->installEventFilter(this);
    newSysPage->txtSysXs->installEventFilter(this);
    newSysPage->txtSysBc->installEventFilter(this);
    newSysPage->txtSysJc->installEventFilter(this);
    newTestPage->widget->installEventFilter(this);
    newAddPage->tabMn->installEventFilter(this);
    newAddPage->tabControl->installEventFilter(this);
    newAddPage->tabChannel->installEventFilter(this);
    newAddPage->tabHarmonic->installEventFilter(this);
    newAddPage->txtUn->installEventFilter(this);
    newAddPage->txtPercent->installEventFilter(this);

    //LM 非同步测量
    newTestPage->f_wcPage->txtBzXdy->installEventFilter(this);     //在窗体上为lineEdit安装过滤器
    newTestPage->f_wcPage->txtBcXdy->installEventFilter(this);
    newTestPage->f_wcPage->txtEdyc->installEventFilter(this);

    newTestPage->f_wcPage->txtTestNum->installEventFilter(this);
    newTestPage->f_wcPage->txtMUYS->installEventFilter(this);
    //LM  非同步测量
    for(int i=0;i<12;i++)
        newAllPage->widget[i]->installEventFilter(this);


    newSysPage->txtbc->installEventFilter(this);
    newSysPage->txtbc1->installEventFilter(this);
    newSysPage->txtbc2->installEventFilter(this);
    newSysPage->txtbc3->installEventFilter(this);
    newSysPage->txtjc->installEventFilter(this);
    newSysPage->txtjc1->installEventFilter(this);
    newSysPage->txtjc2->installEventFilter(this);
    newSysPage->txtjc3->installEventFilter(this);
 //   ui->frakey->setVisible(false);

    createDelFrm();
}

void MainWindow::createDelFrm()
{
    QFont ft;
    ft.setPointSize(12);
    ft.setBold(true);
    delWidget=new QWidget(this);
 //   delWidget->setStyleSheet("background-color:#C2C8C7");
    delWidget->setGeometry(100,100,350,300);
    delWidget->setStyleSheet("background-color:tan;");

    rdoXh=new QRadioButton(tr("按序号删除:"));
    rdoSj=new QRadioButton(tr("按日期删除:"));
    rdoAll=new QRadioButton(tr("全部删除"));
    labXh=new QLabel(tr("序号:"));
    txtXh=new QLineEdit();
    labSj=new QLabel(tr("日期:"));
    txtSj=new QLineEdit();
    btnDelOK=new QPushButton(tr("确定"));
    btnDelCancel=new QPushButton(tr("取消"));
    btnDelOK->setStyleSheet("background-color:gray; color:rgb(0,0,0);");
    btnDelCancel->setStyleSheet("background-color:gray; color:rgb(0,0,0);");

    QHBoxLayout *xhLayout = new QHBoxLayout;
    xhLayout->addWidget(rdoXh);
    xhLayout->addWidget(labXh);
    xhLayout->addWidget(txtXh);
    xhLayout->addStretch(1);
    QHBoxLayout *sjLayout = new QHBoxLayout;
    sjLayout->addWidget(rdoSj);
    sjLayout->addWidget(labSj);
    sjLayout->addWidget(txtSj);
    sjLayout->addStretch(1);
    QHBoxLayout *allLayout = new QHBoxLayout;
    allLayout->addWidget(rdoAll);
    allLayout->addStretch(1);
    QHBoxLayout *btnLayout = new QHBoxLayout;
    btnLayout->addWidget(btnDelOK);
    btnLayout->addWidget(btnDelCancel);
    QVBoxLayout *mLayout = new QVBoxLayout;
    mLayout->addLayout(xhLayout);
    mLayout->addLayout(sjLayout);
    mLayout->addLayout(allLayout);
    mLayout->addLayout(btnLayout);
    delWidget->setLayout(mLayout);
    hideDelFrm();

    connect(btnDelOK,SIGNAL(clicked()),this,SLOT(delWcdata()));
    connect(btnDelCancel,SIGNAL(clicked()),this,SLOT(hideDelFrm()));
    connect(rdoXh,SIGNAL(clicked()),this,SLOT(delSelect()));
    connect(rdoSj,SIGNAL(clicked()),this,SLOT(delSelect()));
    connect(rdoAll,SIGNAL(clicked()),this,SLOT(delSelect()));
    txtXh->installEventFilter(this);
    txtSj->installEventFilter(this);

    //-------------------新建一个扫描列表窗口
  //  sysWidget=new QWidget(this);
  //  sysWidget->setStyleSheet("background-color:#C2C8C7");
  //  sysWidget->setGeometry(500,400,150,100);
    /*
    sysList=new QListWidget(this);
    sysList->addItem(tr("从全站配置中选择"));
    sysList->addItem(tr("从扫描列表中选择"));
    ft.setPointSize(12);
    sysList->setFont(ft);
  //  QVBoxLayout *msLayout = new QVBoxLayout;
 //   msLayout->addWidget(sysList);
  //  sysWidget->setLayout(msLayout);
   // sysList->setLayout(msLayout);
    sysList->setGeometry(460,340,180,60);
    sysList->setVisible(false);
*/
    ft.setPointSize(10);
    wcbjWidget=new QWidget(this);
    wcbjWidget->setStyleSheet("background-color:#00A4E0");
    wcbjWidget->setGeometry(120,100,250,200);
    tabWcbj=new QTableView();
    modela = new QStandardItemModel();
    tabWcbj->setFont(ft);
    tabWcbj->setEditTriggers(QTableView::NoEditTriggers);//设置非编辑状态
    tabWcbj->setSelectionBehavior(QTableView::SelectRows);//设置点击行为行
    tabWcbj->setShowGrid(true);   //显示中间的线

     modela->setColumnCount(3);
     modela->setRowCount(0);
     modela->setHeaderData(0,Qt::Horizontal,tr("次数"));
     modela->setHeaderData(1,Qt::Horizontal,tr("比差"));
     modela->setHeaderData(2,Qt::Horizontal,tr("角差"));

   //  tabWc->horizontalHeader()->hide();
     tabWcbj->verticalHeader()->hide();
     tabWcbj->setModel(modela);
     tabWcbj->resizeColumnsToContents();
     tabWcbj->setColumnWidth(0,50);
     tabWcbj->setColumnWidth(1,80);
     tabWcbj->setColumnWidth(2,80);
     QVBoxLayout *nLayout = new QVBoxLayout;
     nLayout->addWidget(tabWcbj);
     wcbjWidget->setLayout(nLayout);
     wcbjWidget->setVisible(false);

}
void MainWindow::showDelFrm()
{
    dataFlag=0;
    labXh->setText(tr("按序号删除:"));
    labSj->setText(tr("按时间删除:"));
    rdoXh->setText(tr("按序号删除:"));
    rdoSj->setText(tr("按日期删除:"));
    rdoAll->setText(tr("全部删除"));
    rdoXh->setChecked(true);
    labXh->setVisible(true);
    txtXh->setVisible(true);
    labSj->setVisible(false);
    txtSj->setVisible(false);
    txtXh->setText(newWcPage->txtXuhao->text());
    delWidget->show();
}
void MainWindow::hideDelFrm()
{
    delWidget->hide();
}
void MainWindow::dataFind()
{
    dataFlag=1;
    labXh->setText(tr("按序号查找:"));
    labSj->setText(tr("按时间查找:"));
    rdoXh->setText(tr("按序号查找:"));
    rdoSj->setText(tr("按日期查找:"));
    rdoAll->setText(tr("全部查找"));
    rdoXh->setChecked(true);
    labXh->setVisible(true);
    txtXh->setVisible(true);
    labSj->setVisible(false);
    txtSj->setVisible(false);
    txtXh->setText(newWcPage->txtXuhao->text());
    delWidget->show();
}

void MainWindow::delSelect()
{
    if (rdoXh->isChecked())
    {
        labXh->setVisible(true);
        txtXh->setVisible(true);
        labSj->setVisible(false);
        txtSj->setVisible(false);
    }
    else if (rdoSj->isChecked())
    {
        labXh->setVisible(false);
        txtXh->setVisible(false);
        labSj->setVisible(true);
        txtSj->setVisible(true);
    }
    else if (rdoAll->isChecked())
    {
        labXh->setVisible(false);
        txtXh->setVisible(false);
        labSj->setVisible(false);
        txtSj->setVisible(false);
    }
}

void MainWindow::startTimer()
{
    delShowtimer->start(3000);
}
void MainWindow::stopTimer()
{
    delShowtimer->stop();
}
void MainWindow::showDelAllMsg()
{
    delShowtimer->stop();
    if (dataCount==0)
        return;

    int ret = myHelper::ShowMessageBoxQuesion("确定要删除所有的记录?");
  //  int ret=QMessageBox :: warning ( NULL , "警告" , "确定要删除所有的记录?" , QMessageBox :: Yes | QMessageBox :: No , QMessageBox :: Yes ) ;
    if (ret==1)
    {
        myDB->DelAll();
        showNull();
        dataCount=0;
    }
}

void MainWindow::wcsjPage()
{
    if (m_iFlag == 1)
    {
        f_paraReturn();
        //paraReturn();
    }
    else if (m_iFlag!=newTestPage->tabwc->currentIndex())
    {
        paraReturn();
    }

    newTestPage->btnAll->setVisible(false);
    if (newTestPage->tabwc->currentIndex()==0)      //误差测量
    {
        newTestPage->btnTest->setText(tr("开始"));
        newTestPage->btnTest->setVisible(true);
        if (newTestPage->cboBcSelect->currentIndex()==5)
            newTestPage->btnAll->setVisible(true);
    }
    else if (newTestPage->tabwc->currentIndex() == 1)
    {
        newTestPage->btnTest->setText(tr("开始"));
        newTestPage->btnTest->setVisible(true);
    }
    else if (newTestPage->tabwc->currentIndex()==2)     //误差数据
    {
        newTestPage->btnTest->setVisible(false);
        dataCount=myDB->getWcxxCount();
        tbWcxx=myDB->openWcxx();
        if (tbWcxx.last())
            showWcdata();
        else
            newTestPage->labDataCount->setText(tr("无数据"));
    }
    else if(newTestPage->tabwc->currentIndex()==3)     //加量输出
    {
        if(sourceIsActive)
        {
            newTestPage->btnTest->setText(tr("降源"));
        }
        else
        {
            newTestPage->btnTest->setText(tr("升源"));
        }

        newTestPage->btnTest->setVisible(true);
    }
    else if(newTestPage->tabwc->currentIndex()==4)     //录波
    {
        newTestPage->btnTest->setText(tr("录波"));
        newTestPage->btnTest->setVisible(true);
        newLuboPage->btnLuboData->setEnabled(true);
    }
    else if(newTestPage->tabwc->currentIndex()==5)     //MU测量
    {
        newTestPage->btnTest->setText(tr("开始"));
        newTestPage->btnTest->setVisible(true);
    }
    else if(newTestPage->tabwc->currentIndex()==6)     //系统设置
    {
        newTestPage->btnTest->setText(tr("开始"));
        newTestPage->btnTest->setVisible(false);
    }
    m_iFlag=newTestPage->tabwc->currentIndex();
}

void MainWindow::bwStart()
{
    if (newTestPage->btnTest->text()=="停止")
    {
        newTestPage->btnTest->setText(tr("开始"));
        paraReturn();

//        if(newBwjyPage->tabWidget->currentIndex() == 0)
//        {
//            udp->UdpSendCmd("stop",5);
//            udp->setRead(false);
//        }
        return;
    }
    writeXBdata(-1);   //置空
 //   cappacket=new CapPacket(this);

    if (newBwjyPage->tabWidget->currentIndex()==2)  //谐波分析
    {
        // qDebug()<<"ui is ok!";
        cappacket->StopCap(false);
        openNetFlag=cappacket->Open(newTestPage->cboCyfs->currentIndex());
        openNetTimer->start(1000);
        if(!openNetFlag)
        {
         //   QMessageBox::information(NULL,"初始化结果","初始化失败！");
            myHelper::ShowMessageBoxError(tr("初始化失败！"));
         //   newBwjyPage->btnBwStart->setEnabled(true);
         //   newBwjyPage->btnBwStop->setEnabled(false);
            return;
        }
        else
        {
            openNetTimer->stop();
            openNetFlag=false;
        }
        cappacket->setTestType(0);
        cappacket->StopCap(false);
        cappacket->setIsOK(false);
        guiyue=cappacket->GuiYueType();

        int iTongDaoHao=newBwjyPage->cboTdh->currentText().toInt();

        if(guiyue == GuiYue9_1)
        {
            dblFuZhi_HGQ = 11585;
        }
        else if(guiyue == GuiYue9_2)
        {
            if(newTestPage->cboCTPT->currentIndex()==0)		// 如果是CT测量
                dblFuZhi_HGQ = myDB->edyc_dl.toInt() * 1000;
            else
            {
                dblFuZhi_HGQ = myDB->edyc_dy.toDouble()/1.73205 * 100000;
            }
        }
        bwFlag=1;
        cappacket->SetCapParamater(iTongDaoHao-1,iZHOUQI,0,dblFuZhi_HGQ);//通道，周期,起始位,幅值
        cappacket->setTestChannel(iTongDaoHao-1);
        cappacket->setTestSelect(1);
        int iChannel=iTongDaoHao;
        iChannel %=12;
        if (iChannel==0)
            iChannel=12;
        for(int i=0;i<12;i++)
        {
            if (i==iChannel-1)
                cappacket->SetChannelShow(i,true);
            else
                cappacket->SetChannelShow(i,false);
        }
    }
    else
    {
        bwFlag=-1;
        cappacket->SetCapParamater(TestChannel_PinLv,1,0,11585);   //(TestChannel_PinLv,iZHOUQI,0,11585)
    }

    if (newBwjyPage->tabWidget->currentIndex()==0)      //延时时间测量
    {

      //  cappacket->setiType(1);
        newBwjyPage->txtYs->setText("");
        newBwjyPage->txtMaxYs->setText("");
        newBwjyPage->txtMinYs->setText("");
        newBwjyPage->txtAvgYs->setText("");
        newBwjyPage->txtMaxJg->setText("");
        newBwjyPage->txtMinJg->setText("");

        newBwjyPage->txtBwAll->setText("");
        newBwjyPage->txtBwLost->setText("");
        newBwjyPage->txtBwError->setText("");
        m_iDelayNum=0;
        delayMin=0;
        delayMax=0;
        delayAvg=0;
        lsMin=0;
        lsMax=0;
        m_dblBwAll=0;
        m_iBwLost=0;
        m_iBwError=0;
        iYsNum=0;
        QString s=newBwjyPage->cboTime->currentText();
        int iwz=s.indexOf("*");
        if (iwz>=0)
        {
            s=s.left(iwz);
            iYsNum=s.toInt()*60*60;
        }
        else
        {
            iYsNum=s.toInt()*60;
        }
        ysTimer->start(1000);
        newTestPage->iNetPort = newBwjyPage->cboInput->currentIndex();

        udp->UdpSendCmd("start",6);
        udp->setRead(true);

        udpOrder(0);

        packet_testing = true;
    }
    else if(newBwjyPage->tabWidget->currentIndex()==1)      //对时守时测量
    {

        //when get ds_error from SMV packets, set iNetPort to light-2
        newTestPage->iNetPort = 2;

        newBwjyPage->txtDs->setText("0.000");
        newBwjyPage->txtMaxDs->setText("0.000");
        newBwjyPage->txtSs->setText("0.000");
        newBwjyPage->txtMaxSs->setText("0.000");

        if(newBwjyPage->beginDsTesting->isChecked())
        {
            switch(newBwjyPage->combTestingTime->currentIndex())
            {
            case 0:
                    iDsNum = 10;break;
            case 1:
                    iDsNum = 30;break;
            case 2:
                    iDsNum = 60;break;
            case 3:
                    iDsNum = 600;break;
            case 4:
                    iDsNum = 3600;break;
            default:
                    iDsNum = 0;break;
            }
        }
        else
        {
            switch(newBwjyPage->combTestingTime->currentIndex())
            {
            case 0:
                    iDsNum = 300;break;
            case 1:
                    iDsNum = 600;break;
            case 2:
                    iDsNum = 1800;break;
            case 3:
                    iDsNum = 3600;break;
            case 4:
                    iDsNum = 24*3600;break;
            default:
                    iDsNum = 0;
            }
        }
//        iDsNum= newBwjyPage->txtDsTime->text().toInt();
//        iSsNum= newBwjyPage->txtSsTime->text().toInt();
        dsMax=0;
        ssMax=0;
        dds=0;
        dsstemp=0;
        iDsFlag=0; //0 对时,1 守时

        if (iDsNum<=0)
        {
            QMessageBox::information(NULL,"错误","time is undefined！");
            return;
        }

        iDsNum_static = iDsNum;
        iDsNum = 0;

        // newBwjyPage->beginDsTesting->setCheckable(false);
        // newBwjyPage->beginSsTesting->setCheckable(false);

        dsTimer->start(1000); // refresh the displayed result per second

        newTestPage->itype=newBwjyPage->cboBzsz->currentIndex();
        newTestPage->itime=iDsNum;

        udpOrder(3);
        udp->UdpSendCmd("start",6);
        udp->setRead(true);
    }
    else
    {
        cappacket->setiType(2);
        bwTimer->start(100);
        cappacket->setMacGl(1);
        cappacket->start();
    }

    /*
    else if(newBwjyPage->tabWidget->currentIndex()==1)      //对时守时测量
    {

        //when get ds_error from SMV packets, set iNetPort to light-2
        newTestPage->iNetPort = 2;

        newBwjyPage->txtDs->setText("0.000");
        newBwjyPage->txtMaxDs->setText("0.000");
        newBwjyPage->txtSs->setText("0.000");
        newBwjyPage->txtMaxSs->setText("0.000");

        if(newBwjyPage->beginDsTesting->isChecked())
        {
            switch(newBwjyPage->combTestingTime->currentIndex())
            {
            case 0:
                    iDsNum = 10;break;
            case 1:
                    iDsNum = 30;break;
            case 2:
                    iDsNum = 60;break;
            case 3:
                    iDsNum = 600;break;
            case 4:
                    iDsNum = 3600;break;
            default:
                    iDsNum = 0;break;
            }
        }
        else
        {
            switch(newBwjyPage->combTestingTime->currentIndex())
            {
            case 0:
                    iDsNum = 300;break;
            case 1:
                    iDsNum = 600;break;
            case 2:
                    iDsNum = 1800;break;
            case 3:
                    iDsNum = 3600;break;
            case 4:
                    iDsNum = 24*3600;break;
            default:
                    iDsNum = 0;
            }
        }
//        iDsNum= newBwjyPage->txtDsTime->text().toInt();
//        iSsNum= newBwjyPage->txtSsTime->text().toInt();
        dsMax=0;
        ssMax=0;
        dds=0;
        dsstemp=0;
        iDsFlag=0; //0 对时,1 守时

        if (iDsNum<=0)
        {
            QMessageBox::information(NULL,"错误","time is undefined！");
            return;
        }

        iDsNum_static = iDsNum;
        iDsNum = 0;

        // newBwjyPage->beginDsTesting->setCheckable(false);
        // newBwjyPage->beginSsTesting->setCheckable(false);

        dsTimer->start(1000); // refresh the displayed result per second

        newTestPage->itype=newBwjyPage->cboBzsz->currentIndex();
        newTestPage->itime=iDsNum;

        udpOrder(3);
    }
    else
    {
        cappacket->setiType(2);
        bwTimer->start(100);
        cappacket->setMacGl(1);
        cappacket->start();
    }*/

    newTestPage->btnTest->setText(tr("停止"));
}

void MainWindow::setTestSelect(bool f)
{
    newTestPage->cboTbfs->setEnabled(f);
    newTestPage->cboCTPT->setEnabled(f);
    newTestPage->cboBcSelect->setEnabled(f);
    newTestPage->cboBctd->setEnabled(f);
    newTestPage->cboBhCl->setEnabled(f);
    newTestPage->cboBzSelect->setEnabled(f);
    newTestPage->cboCyfs->setEnabled(f);
    newTestPage->cboEdycDw->setEnabled(f);
    newTestPage->cboInput->setEnabled(f);
    newTestPage->cboJD->setEnabled(f);
    newTestPage->cboSave->setEnabled(f);
    newTestPage->txtEdyc->setEnabled(f);
    newTestPage->btnGet->setEnabled(f);
    newTestPage->txtBzXdy->setEnabled(f);
    newTestPage->txtBcXdy->setEnabled(f);
    newTestPage->txtTestNum->setEnabled(f);
//    newTestPage->harmonicTest->setEnabled(f);
}

void MainWindow::slotDs()
{
    QString s="";

    double dss;
    static double tmp;

    static int error_times = 0;

    if (iDsNum < iDsNum_static) // if iDsNum do not reach the testing-time
    {
        iDsNum++;

        if((iDsNum) < 5) // in first 5 seconds, do nothing
        {
            newBwjyPage->labInfoDs->setText("数据采集中...");

            jdys_avg = udp->getDs();

            dsMax = jdys_avg - tmp;

            tmp = udp->getDs();

            error_times = 0;

            return;
        }

        // jdys = time_delay
        // delta(time_delay) = jdys - jdys_old
        // 1s_packet = 1s_stand + delta(time_delay)
        // wc_packet = 1s_packet - 1s_stand = delta(time_delay)
        if( newBwjyPage->beginDsTesting->isChecked() )
        {
            s=tr("正在测试对时误差,剩余 ");

            jdys_avg = jdys_avg * (iDsNum - 1)/iDsNum + tmp/iDsNum;

            dds = tmp - jdys_avg; // the true-value is avg of sample

            if(std::abs(dds) - std::abs(dsMax) > 100) // if the dds is too large, abort it
            {
                error_times ++;

                if( error_times == 5)
                {
                    dsTimer->stop();
                    s=tr("出现错误,请重新开始测试!");
                    newBwjyPage->labInfoDs->setText(s);
                    error_times = 0;
                    udpOrder(0);

                    udp->UdpSendCmd("stop",5);
                }

                return;
            }
        }
        else
        {
            s=tr("正在测试守时误差,剩余 ");

            dds = tmp - jdys_avg;

            if(std::abs(dds) - std::abs(dsMax) > 100) // if the dds is too large, abort it
            {
                error_times ++;

                if( error_times == 5)
                {
                    dsTimer->stop();
                    s=tr("出现错误,请重新开始测试!");
                    newBwjyPage->labInfoDs->setText(s);
                    error_times = 0;
                    udpOrder(0);

                    udp->UdpSendCmd("stop",5);
                }

                return;
            }
        }

        tmp = udp->getDs();

        s+=QString::number(iDsNum_static - iDsNum);
        s+=tr(" 秒");

        if(std::abs(dds) > std::abs(dsMax))
        {
            dsMax = dds;
        }

        if(newBwjyPage->beginDsTesting->isChecked())
        {
            newBwjyPage->labCurrentJDYS->setText(QString::number(jdys_avg+dds,'f',3));
            // newBwjyPage->labCurrentJDYS_avg->setText(QString::number(jdys_avg,'f',3));
            newBwjyPage->labCurrentJDYS_avg->setText(QString::number(udp->delay_specified,'f',3));
            newBwjyPage->txtDs->setText(QString::number(dds,'f',3));
            newBwjyPage->txtMaxDs->setText(QString::number(dsMax,'f',3));
        }
        else
        {
            newBwjyPage->labCurrentJDYS->setText(QString::number(jdys_avg+dds,'f',3));
            newBwjyPage->txtSs->setText(QString::number(dds,'f',3));
            newBwjyPage->txtMaxSs->setText(QString::number(dsMax,'f',3));
        }

        if (m_bIsConn)          //联机时上传误差数据;
        {
            QString s="2a:";
            s += newBwjyPage->labCurrentJDYS->text();
            s += ":";
            s += newBwjyPage->labCurrentJDYS_avg->text();
            s += ":";
            s += newBwjyPage->txtDs->text();
            s += ":";
            s += newBwjyPage->txtMaxDs->text();
            s += ":";
            s += newBwjyPage->txtSs->text();
            s += ":";
            s += newBwjyPage->txtMaxSs->text();

            tcpServer->TcpSend(s);
        }
    }
    else// if (iDsNum==iDsNum_static) // duishi testing is over
    {
      //  iDsNum--;
        if (dsMax==0.0)
        {
            s=tr("测试结果异常！测量结束");
        }
        else
        {
            s=tr("测试结束");
        }

        dds = 0;
        dsMax = 0;
        error_times = 0;
        dsTimer->stop();
        newTestPage->btnTest->setText(tr("开始"));
        showInfoTimer->start(2000);
        udpOrder(0);

        udp->UdpSendCmd("stop",5);
    }

    newBwjyPage->labInfoDs->setText(s);
    /*
    if(m_bIsConn)
    {
        QString s="3c";
        s += QString::number(dds,'f',3)+",";
        s += QString::number(dsMax,'f',3)+",";
        s += QString::number(std::abs(dss),'f',3)+",";
        s += QString::number(std::abs(ssMax),'f',3)+",";
        tcpServer->TcpSend(s);
    }
    */
}
void MainWindow::slotYs()
{
    QString s=tr("正在测试,剩余 ");
    if (iYsNum>0)
    {
        iYsNum--;
        s +=QString::number(iYsNum);
        s += tr(" 秒");
    }
    else
    {
        ysTimer->stop();
        s=tr("测试结束");
        newTestPage->btnTest->setText(tr("开始"));
        showInfoTimer->start(2000);
        udpOrder(0);

        udp->UdpSendCmd("stop",5);
        udp->setRead(false);

        packet_testing = false;
    }
    newBwjyPage->labInfo->setText(s);
}

void MainWindow::bwStop()
{
    if (newTestPage->btnTest->text()=="停止")
    {
        newTestPage->btnTest->setText(tr("开始"));
    }

  //  isTested=false;
    dsTimer->stop();
    cappacket->StopCap(true);
    bwTimer->stop();
  //  newBwjyPage->btnBwStart->setEnabled(true);
  //  newBwjyPage->btnBwStop->setEnabled(false);
    udpOrder(0);
    udp->UdpSendCmd("stop",5);
    udpTimer->stop();
}
void MainWindow::showBwinfo()
{
    newBwjyPage->txtDzl->setText(QString::number(cappacket->getLost()));
}

void MainWindow::showWcdata()
{
    QString datainfo="";
    datainfo=tr("第")+QString::number(tbWcxx.at()+1)+tr("条记录,");
    datainfo+=tr("共")+QString::number(dataCount)+tr("条记录");
    newTestPage->labDataCount->setText(datainfo);
  // qDebug()<< tbWcxx.at();
   // if (tbWcxx.next())
  //  {
        newTestPage->txtXuhao->setText(tbWcxx.value(0).toString());
        newTestPage->txtTbfs->setText(tbWcxx.value(1).toString());
        newTestPage->txtBzxz->setText(tbWcxx.value(2).toString());
        newTestPage->txtBcxz->setText(tbWcxx.value(3).toString());
        newTestPage->txtDate->setText(tbWcxx.value(5).toString());
        if(tbWcxx.value(4).toString()=="")
        {
            newTestPage->labYc->setVisible(false);
            newTestPage->labYcDw->setVisible(false);
            newTestPage->txtYc->setVisible(false);
        }
        else
        {
            newTestPage->labYc->setVisible(true);
            newTestPage->labYcDw->setVisible(true);
            newTestPage->txtYc->setVisible(true);
            QString yc=tbWcxx.value(4).toString();
            if (yc.left(1)=="I")
            {
                newTestPage->labYc->setText(tr("额定一次电流"));
                newTestPage->labYcDw->setText("A");
            }
            else
            {
                newTestPage->labYc->setText(tr("额定一次电压"));
                newTestPage->labYcDw->setText("kV");
            }
            yc=yc.mid(1);
            newTestPage->txtYc->setText(yc);
        }
        tbWcdata=myDB->openWcdata(tbWcxx.value(0).toString());
        newTestPage->model->clear();
        newTestPage->model->setColumnCount(6);
        newTestPage->model->setHeaderData(0,Qt::Horizontal,tr("检定点"));
        newTestPage->model->setHeaderData(1,Qt::Horizontal,tr("被测百分点"));
        newTestPage->model->setHeaderData(2,Qt::Horizontal,tr("标准有效值"));
        newTestPage->model->setHeaderData(3,Qt::Horizontal,tr("被测有效值"));
        newTestPage->model->setHeaderData(4,Qt::Horizontal,tr("比差(%)"));
        newTestPage->model->setHeaderData(5,Qt::Horizontal,tr("角差(′)"));
        newTestPage->tabWcData->setModel(newTestPage->model);
        newTestPage->tabWcData->setColumnWidth(0,90);
        newTestPage->tabWcData->setColumnWidth(1,85);
        newTestPage->tabWcData->setColumnWidth(2,130);
        newTestPage->tabWcData->setColumnWidth(3,130);
        newTestPage->tabWcData->setColumnWidth(4,100);
        newTestPage->tabWcData->setColumnWidth(5,100);
        newTestPage->tabWcData->setColumnHidden(1,true);
        while (tbWcdata.next())
        {
            QStandardItem* item1=new QStandardItem();
            item1->setTextAlignment(Qt::AlignCenter);
            QStandardItem* item2=new QStandardItem();
            item2->setTextAlignment(Qt::AlignCenter);
            QStandardItem* item3=new QStandardItem();
            item3->setTextAlignment(Qt::AlignCenter);
            QStandardItem* item4=new QStandardItem();
            item4->setTextAlignment(Qt::AlignCenter);
            QStandardItem* item5=new QStandardItem();
            item5->setTextAlignment(Qt::AlignCenter);
            QStandardItem* item6=new QStandardItem();
            item6->setTextAlignment(Qt::AlignCenter);

            item1->setText(tbWcdata.value(1).toString());
            item2->setText(tbWcdata.value(2).toString());
            item3->setText(tbWcdata.value(3).toString());
            item4->setText(tbWcdata.value(4).toString());
            item5->setText(tbWcdata.value(5).toString());
            item6->setText(tbWcdata.value(6).toString());

            QList<QStandardItem*> item;
            item << item1<< item2<< item3<< item4<< item5<< item6;
            newTestPage->model->appendRow(item);
            newTestPage->tabWcData->setModel(newTestPage->model);
        }
 //   }
}
void MainWindow::dataFirst()
{
    if (dataCount>0)
    {
        if(!tbWcxx.first())
     //       QMessageBox::information(NULL,tr("数据移动"),tr("已经是第一条了!"));
            myHelper::ShowMessageBoxInfo(tr("已经是第一条了!"));
        else
            showWcdata();
    }
}
void MainWindow::dataPrevious()
{
    if (dataCount>0)
    {
        if(!tbWcxx.previous())
        {
        //    QMessageBox::information(NULL,tr("数据移动"),tr("已经是第一条了!"));
            myHelper::ShowMessageBoxInfo(tr("已经是第一条了!"));
            tbWcxx.next();
        }
        else
            showWcdata();
    }
}
void MainWindow::dataNext()
{
    if (dataCount>0)
    {
        if(!tbWcxx.next())
        {
          //  QMessageBox::information(NULL,tr("数据移动"),tr("已经是最后一条了!"));
            myHelper::ShowMessageBoxInfo(tr("已经是最后一条了!"));
            tbWcxx.previous();
        }
        else
            showWcdata();
    }
}
void MainWindow::dataLast()
{
    if (dataCount>0)
    {
        if(!tbWcxx.last())
            myHelper::ShowMessageBoxInfo(tr("已经是最后一条了!"));
        //    QMessageBox::information(NULL,tr("数据移动"),tr("已经是最后一条了!"));
        else
            showWcdata();
    }
}
void MainWindow::saveWcdata()
{
    QString info="";
    if(isSaved)
    {
        QString tbfs=newTestPage->cboTbfs->currentText();
        QString bzxz=newTestPage->cboBzSelect->currentText();
        QString edyc="";
        if (newTestPage->cboBzSelect->currentIndex()==4)
        {
            bzxz+=",";
            bzxz+=newTestPage->txtBzXdy->text();
            bzxz+="V";
        }
        QString bcxz=newTestPage->cboBcSelect->currentText();
        if (newTestPage->cboBcSelect->currentIndex()==4)
        {
            bcxz+=",";
            bcxz+=newTestPage->txtBzXdy->text();
            bcxz+="V";
        }
        else if(newTestPage->cboBcSelect->currentIndex()==5)
        {
            bcxz+=",通道：";
            bcxz+=newTestPage->cboBctd->currentText();
          //  bcxz+="通道";
            if (newTestPage->cboCTPT->currentIndex()==0)
            {
                edyc+="I";
                edyc+=newTestPage->txtEdyc->text();
            }
            else
            {
                edyc+="U";
                edyc+=newTestPage->txtEdyc->text();
            }
        }
        nowXh=myDB->insertWcxx(tbfs,bzxz,bcxz,edyc);
        isSaved=false;
    }
    if (nowXh=="")
        return;
    QString bcbfd1="";
    QString bzyxz1="";
    QString bcyxz1="";
    QString bc1="";
    QString jc1="";

    bcbfd1=newTestPage->txtBFB->text();
    bzyxz1=newTestPage->txtBzYxz->text();
    bcyxz1=newTestPage->txtBcYxz->text();
    bc1=newTestPage->txtBc->text();
    jc1=newTestPage->txtJc->text();
    if (preBFD=="")
    {
        preBFD=newTestPage->txtBFB->text();
        myDB->insertWcdata(nowXh,preBFD,bcbfd1,bzyxz1,bcyxz1,bc1,jc1);
        info=tr("数据已存储！");
    }
    else
    {
        double bfd=0;
        bfd=std::abs((newTestPage->txtBFB->text().toDouble()-preBFD.toDouble())/preBFD.toDouble());
        preBFD=newTestPage->txtBFB->text();
        if (bfd>=0.01)
        {
            myDB->insertWcdata(nowXh,preBFD,bcbfd1,bzyxz1,bcyxz1,bc1,jc1);
            info=tr("数据已存储！");
        }
        else
        {
            myDB->updateWcdata(nowXh,preBFD,bcbfd1,bzyxz1,bcyxz1,bc1,jc1);
            info=tr("数据已覆盖存储！");
        }
    }
    QDateTime qdatetime=QDateTime::currentDateTime();
    QString date=qdatetime.toString("yyyy-MM-dd")+" "+qdatetime.toString("hh:mm:ss");
    myDB->updateWcxxDate(nowXh,date);
    newTestPage->labInfo->setText(info);
    showInfoTimer->start(2000);

}

void MainWindow::delWcdata()
{
    if (dataFlag==1)            //查找
    {
        QString sql;
        QString sql1;
        if (rdoXh->isChecked())
        {
            sql="select * from wcxx where xh='"+txtXh->text() +"'";
            sql1="where xh='"+txtXh->text() +"'";
            tbWcxx=myDB->openWcxxforSql(sql);
            if (!tbWcxx.next())
            {
              //  QMessageBox::information( NULL , "信息" , "无此记录！" );
                myHelper::ShowMessageBoxInfo(tr("无此记录！"));
                showNull();
            }
            else
            {
                dataCount=myDB->getWcxxCountForSql(sql1);
                showWcdata();
            }
        }
        else if (rdoSj->isChecked())
        {
            sql="select * from wcxx where date(date)=date('"+txtSj->text()+"')";
            sql1="where date(date)=date('"+txtSj->text()+"')";
            tbWcxx=myDB->openWcxxforSql(sql);
            if (!tbWcxx.next())
            {
           //     QMessageBox::information( NULL , "信息" , "无此记录！" );
                myHelper::ShowMessageBoxInfo(tr("无此记录！"));
                showNull();
            }
            else
            {
                dataCount=myDB->getWcxxCountForSql(sql1);
                showWcdata();
            }
        }
        else if (rdoAll->isChecked())
        {
            sql="select * from wcxx";
            tbWcxx=myDB->openWcxxforSql(sql);
            if (!tbWcxx.next())
            {
              //  QMessageBox::information( NULL , "信息" , "无此记录！" );
                myHelper::ShowMessageBoxInfo(tr("无此记录！"));
                showNull();
            }
            else
            {
                dataCount=myDB->getWcxxCount();
                showWcdata();
            }
        }
        hideDelFrm();
        return;
    }
    if (dataCount>0)
    {
        if (rdoAll->isChecked())
        {
            showDelAllMsg();
            hideDelFrm();
            return;
        }
        int ret=myHelper::ShowMessageBoxQuesion(tr("确定要删除此条记录?"));

     //   int ret=QMessageBox :: warning ( NULL , "警告" , "确定要删除此条记录?" , QMessageBox :: Yes | QMessageBox :: No , QMessageBox :: Yes ) ;
        if (ret==1)
        {
         //   myDB->delWc(newWcPage->txtXuhao->text());
           int delNum=0;
           QString sql;
           if (rdoXh->isChecked())
           {
               sql="select * from wcxx where xh='"+txtXh->text() +"'";
               tbWcxx=myDB->openWcxxforSql(sql);
               if (tbWcxx.next())
               {
                   myDB->delWc(txtXh->text());
                   delNum=1;
               }
           }
           else if (rdoSj->isChecked())
           {
               sql="select COUNT(*) from wcxx where date(date)=date('"+txtSj->text() +"')";
               tbWcxx=myDB->openWcxxforSql(sql);
               if (tbWcxx.next())
               {
                 delNum =  tbWcxx.value(0).toInt();
               }
               for(int i=0;i<delNum;i++)
               {
                   sql="select * from wcxx where date(date)=date('"+txtSj->text()+"')";
                   tbWcxx=myDB->openWcxxforSql(sql);
                   if (tbWcxx.next())
                   {
                        QString bh=tbWcxx.value(0).toString();
                        myDB->delWc(bh);
                   }
               }
           }
            dataCount= dataCount -delNum;
            tbWcxx=myDB->openWcxx();
            if (dataCount>0)
            {
             //   if(dataCount>=newWcPage->txtXuhao->text().toInt())
             //       tbWcxx.seek(newWcPage->txtXuhao->text().toInt()-1);
             //   else
                    tbWcxx.last();
                showWcdata();
            }
            else
                showNull();
        }
    }
    hideDelFrm();
}
void MainWindow::showNull()
{
    newWcPage->txtXuhao->setText("");
    newWcPage->txtBzxz->setText("");
    newWcPage->txtBcxz->setText("");
    newWcPage->txtTbfs->setText("");
    newWcPage->txtYc->setText("");
    newWcPage->txtDate->setText("");
    newWcPage->model->clear();
    newWcPage->model->setColumnCount(6);
    newWcPage->model->setHeaderData(0,Qt::Horizontal,tr("标准百分点"));
    newWcPage->model->setHeaderData(1,Qt::Horizontal,tr("被测百分点"));
    newWcPage->model->setHeaderData(2,Qt::Horizontal,tr("标准有效值"));
    newWcPage->model->setHeaderData(3,Qt::Horizontal,tr("被测有效值"));
    newWcPage->model->setHeaderData(4,Qt::Horizontal,tr("比差(%)"));
    newWcPage->model->setHeaderData(5,Qt::Horizontal,tr("角差(′)"));
    newWcPage->tabWc->setModel(newWcPage->model);
    newWcPage->labDataCount->setText(tr("无数据"));
}
void MainWindow::paraReturn()
{
    fakePPS->stop();

    iTestMode = 0;

    nowtest=-1;
    dsTimer->stop();
    ysTimer->stop();
    openNetTimer->stop();
    openNetFlag=false;
    newTestPage->tabwc->setEnabled(true);
    newTestPage->btnAll->setVisible(false);
    isTested=false;
    bwFlag=-1;

//    if (pwmfd>0)
//        ioctl(pwmfd,0); //蜂鸣器不叫

    cappacket->StopCap(true);
    if (cappacket->IsOpen())
        cappacket->Close();////关闭网口
  //  labInfo->setText(tr(""));
  //  ui->frakey->setVisible(false);
    showAllTimer->stop();
    timer->stop();
    udpTimer->stop();
  //  sysList->setVisible(false);
    wcbjWidget->setVisible(false);
    udp->setSt(false);
    udpOrder(0);

    udp->UdpSendCmd("stop",5);
    udp->setRead(false);

    packet_testing = false;

    setTestSelect(true);

    cappacket->harmonicOrder = 0;
    udp->harmonicOrder = 0;
}

void MainWindow::udpOrder(int flag)
{
    int ilen;
    udpResendNum=0;
    if (flag<10)
        ilen=newTestPage->getStructLen();
    else
        ilen=newAddPage->getStructAddLen();
    cUdpSend=(char*)malloc(ilen);
    if (flag<10)
        newTestPage->getsendUdp(cUdpSend,flag);   //flag==0复位命令 flag==1延时时间测量命令
    else
        newAddPage->getsendUdpAdd(cUdpSend,flag);
    m_iFuwei=flag;

    if(flag == 3)
    {
        udp->UdpSendByte(cUdpSend,ilen);

        udp->setRead(true);
    }
    else
    {
        udp->UdpSendByte(cUdpSend,ilen);

        if (flag==0)            //复位命令重发一次
        {
            newTestPage->getsendUdp(cUdpSend,flag);   //flag==0复位命令
        }
        else
        {
            udpTimer->start(2000);
            udp->setRead(true);
        }
    }
}

void MainWindow::showDelayText()
{
    double m_yanshi=udp->getYanshi();
    int m_min=udp->getJgMin();
   // qDebug()<<m_min;
    int m_max=udp->getJgMax();
    int m_bwall=udp->getbwAll();
    int m_bwlost=udp->getbwLost();
    int m_bwerror=udp->getbwError();
    //double m_avg=udp->getJgAvg();

    double error1 = udp->error1 / 100.0;
    double error2 = udp->error2 / 100.0;
    double error3 = udp->error3 / 100.0;
    double error4 = udp->error4 / 100.0;

    m_iDelayNum++;
    if (m_iDelayNum==1)
    {
        delayMin=m_yanshi;
        delayMax=m_yanshi;
        lsMin=m_min;
        lsMax=m_max;
        m_dblBwAll=m_bwall;
        m_iBwLost=m_bwlost;
        m_iBwError=m_bwerror;
    }
    else
    {
        if (m_yanshi>delayMax)
            delayMax=m_yanshi;
        if(m_yanshi<delayMin)
            delayMin=m_yanshi;
        if (m_max>lsMax)
            lsMax=m_max;
        if (m_min<lsMin)
            lsMin=m_min;
        m_dblBwAll += m_bwall;
        m_iBwLost += m_bwlost;
        m_iBwError += m_bwerror;
    }
    delayAvg +=m_yanshi;

    newBwjyPage->txtYs->setText(QString::number(m_yanshi/10,'f',1));
    newBwjyPage->txtMaxYs->setText(QString::number(delayMax/10,'f',1));
    newBwjyPage->txtMinYs->setText(QString::number(delayMin/10,'f',1));
    newBwjyPage->txtAvgYs->setText(QString::number((delayAvg/m_iDelayNum)/10,'f',1));
    newBwjyPage->txtMaxJg->setText(QString::number((float)lsMax/10,'f',1));
    newBwjyPage->txtMinJg->setText(QString::number(lsMin/10,'f',1));
    //newBwjyPage->txtBwAll->setText(QString::number(m_dblBwAll,''));
    newBwjyPage->txtBwAll->setText(QString::number(m_bwall,10));
    newBwjyPage->txtBwLost->setText(QString::number(m_bwlost));
    newBwjyPage->txtBwError->setText(QString::number(m_bwerror));

    newBwjyPage->txterror1->setText(QString::number(error1,'f',2));
    newBwjyPage->txterror2->setText(QString::number(error2,'f',2));
    newBwjyPage->txterror3->setText(QString::number(error3,'f',2));
    newBwjyPage->txterror4->setText(QString::number(error4,'f',2));

    if (m_bIsConn)
    {
        QString s="2c:";

        s += ":" + newBwjyPage->txtBwAll->text();
        s += ":" + newBwjyPage->txtBwLost->text();
        s += ":" + newBwjyPage->txtBwError->text();

        s += ":" + newBwjyPage->txterror1->text();
        s += ":" + newBwjyPage->txterror2->text();
        s += ":" + newBwjyPage->txterror3->text();
        s += ":" + newBwjyPage->txterror4->text();

        tcpServer->TcpSend(s);
    }

}

void MainWindow::slotTcpProcess(int iflag)
{
    if (iflag == 0)           //误差参数设置
    {
        newTestPage->tabwc->setCurrentIndex(0);

        tcpWcSetup();
    }
    if (iflag == 1)
    {
        newTestPage->tabwc->setCurrentIndex(1);

        tcpWcSetup_f();
    }
    else if (iflag==2)          //对时守时参数设置
    {
        newTestPage->tabwc->setCurrentIndex(5);

        newBwjyPage->tabWidget->setCurrentIndex(1);

        tcpDsSetup();
    }
    else if (iflag==4)          //谐波参数设置
    {
        newTestPage->tabwc->setCurrentIndex(5);

        newBwjyPage->tabWidget->setCurrentIndex(2);

        tcpXbSetup();
    }
    else if(iflag==6)           //录波参数设置
    {
        newTestPage->tabwc->setCurrentIndex(4);

        tcpLbSetup();
    }
    else if(iflag==11)      //MU接口参数
    {
        newTestPage->tabwc->setCurrentIndex(5);

        newBwjyPage->tabWidget->setCurrentIndex(0);

        tcpMuSetup();
    }
    else if(iflag==12)      //模拟加量
    {
        newTestPage->tabwc->setCurrentIndex(3);

        newAddPage->rdoMn->setChecked(true);

        tcpMnSetup();
    }
    else if(iflag==13)      //ft3加量
    {
        tcpFt3Setup();
    }
    else if(iflag==14)      //全帧解析
    {
        findSmvMax();
    }
    else if (iflag==10)           //复位
    {
        if(newTestPage->btnTest->text() == "停止")
        {
            newTestPage->btnTest->click();
        }

        if (nowtest>0)
        {
            paraReturn();
            sleep(1);
        }
    }
}

void MainWindow::findSmvMax()
{
    int tdh = tcpServer->getCurrentTd();

    if(tdh==0)
    {
        newTestPage->btnAll->click();
    }
    else if(tdh==99)
    {
        pagesWidget->setCurrentIndex(0);

        if(newTestPage->tabwc->currentIndex() == 1)
        {
            f_paraReturn();
        }
        else
        {
            paraReturn();
        }
    }
    else
    {
        tdh = (tdh / 12) * 12;

        if(tdh < 1) tdh = 1;
        if(tdh > 96) tdh = 90;

        if(newTestPage->tabwc->currentIndex() == 1)//LM  非同步测量
        {
            newTestPage->f_wcPage->cboBctd->setCurrentIndex(tdh);
            newAllPage->setTDH(tdh);
            f_setCSCS();
        }
        else
        {
            newTestPage->cboBctd->setCurrentIndex(tdh);
            newAllPage->setTDH(tdh);
            setCSCS();
        }
    }
}

void MainWindow::tcpWcSetup()
{
    newTestPage->cboTbfs->setCurrentIndex(tcpServer->getTbfs());
    int ictpt=tcpServer->getLx();
    newTestPage->cboCTPT->setCurrentIndex(ictpt);
    newTestPage->txtEdyc->setText(QString::number(tcpServer->getEdyc()));
    int iycdw=tcpServer->getEdycDw();
    //if (ictpt==1)    //电压互感器
    //    iycdw = 1;
    newTestPage->cboEdycDw->setCurrentIndex(iycdw);
    newTestPage->cboJD->setCurrentIndex(tcpServer->getJd());
    int ibz=tcpServer->getBzSelect();
    newTestPage->cboBzSelect->setCurrentIndex(ibz);
    if ((ibz==4)||(ibz==5))     //模拟小电压或者谐波小电压
        newTestPage->txtBzXdy->setText(QString::number(tcpServer->getBzDyz()));
    int ibc=tcpServer->getBcSelect();
    newTestPage->cboBcSelect->setCurrentIndex(ibc);
    if ((ibc==5)||(ibc==6))    //9-1/2或者ft3
        newTestPage->cboBctd->setCurrentIndex(tcpServer->getBcTd());
    int itdlx=tcpServer->getBcTdLx();
    if (ibc==6)     //ft3
    {
        //itdlx =1;
        newTestPage->cboBhCl->setCurrentIndex(itdlx);
    }
    if (ibc==4)         //模拟小电压
        newTestPage->txtBcXdy->setText(QString::number(tcpServer->getBcDyz()));
    if (ibc==5)
    {
        int icyfs=tcpServer->getCyfs();
      //  icyfs = 1;
        newTestPage->cboCyfs->setCurrentIndex(icyfs);

        if (icyfs==1)       //组网方式
        {
            newTestPage->txtMac->setText(tcpServer->getMac());
           // newTestPage->cboInput->setCurrentIndex(tcpServer->getInput());
        }
    }

   // newTestPage->tabwc->setCurrentIndex(0);

    newTestPage->btnTest->click();

    /*
    myDB->setHGQ_Channel(newTestPage->cboBctd->currentIndex()+1);
    myDB->setTBFS(newTestPage->cboTbfs->currentIndex());
    myDB->setBZXZ(newTestPage->cboBzSelect->currentIndex());
    myDB->setBCXZ(newTestPage->cboBcSelect->currentIndex());
    myDB->setBZXDY(newTestPage->txtBzXdy->text());
    myDB->setBCXDY(newTestPage->txtBcXdy->text());
    myDB->setBjcs(newTestPage->txtTestNum->text().toInt());
  //  myDB->setCyys(newTestPage->txtYanshi->text().toInt());
    if(newTestPage->cboCTPT->currentIndex()==0)
        myDB->setCTPT(0);
    else
        myDB->setCTPT(1);
    myDB->setEDYC(newTestPage->txtEdyc->text());
    int imcyfs=newTestPage->cboCyfs->currentIndex();
    myDB->setCyfs(QString::number(imcyfs));
    MAC=newTestPage->txtMac->text();
    myDB->setMac(newTestPage->txtMac->text());
    myDB->setXTCS();
    saveMuinfo();           //保存mac地址等信息
    */
}

void MainWindow::tcpWcSetup_f()
{
    //newTestPage->cboTbfs->setCurrentIndex(tcpServer->getTbfs());
    newTestPage->f_wcPage->txtMUYS->setText(QString::number( tcpServer->getMuDelay()));
    int ictpt=tcpServer->getLx();
    newTestPage->f_wcPage->cboCTPT->setCurrentIndex(ictpt);
    newTestPage->f_wcPage->txtEdyc->setText(QString::number(tcpServer->getEdyc()));
    int iycdw=tcpServer->getEdycDw();
    //if (ictpt==1)    //电压互感器
    //    iycdw = 1;
    newTestPage->f_wcPage->cboEdycDw->setCurrentIndex(iycdw);
    //newTestPage->f_wcPage->cboJD->setCurrentIndex(tcpServer->getJd());
    int ibz=tcpServer->getBzSelect();
    newTestPage->f_wcPage->cboBzSelect->setCurrentIndex(ibz);
    if ((ibz==4)||(ibz==5))     //模拟小电压或者谐波小电压
        newTestPage->f_wcPage->txtBzXdy->setText(QString::number(tcpServer->getBzDyz()));
    int ibc=tcpServer->getBcSelect();
    if(ibc < 5)
    {
        myHelper::ShowMessageBoxError("tcp setup error, wccl_f, ibc is 5 or 6");
    }
    newTestPage->f_wcPage->cboPBcSelect->setCurrentIndex(ibc - 5);
    if ((ibc==5)||(ibc==6))    //9-1/2或者ft3
        newTestPage->f_wcPage->cboBctd->setCurrentIndex(tcpServer->getBcTd());
    int itdlx=tcpServer->getBcTdLx();
    if (ibc==6)     //ft3
    {
        //itdlx =1;
        newTestPage->f_wcPage->cboBhCl->setCurrentIndex(itdlx);
    }

    /*
    if (ibc==4)         //模拟小电压
        newTestPage->f_wcPage->txtBcXdy->setText(QString::number(tcpServer->getBcDyz()));
    */

    if (ibc==5)
    {
        int icyfs=tcpServer->getCyfs();

        newTestPage->f_wcPage->cboCyfs->setCurrentIndex(icyfs);
        if (icyfs==1)       //组网方式
        {
            newTestPage->f_wcPage->txtMac->setText(tcpServer->getMac());
            newTestPage->f_wcPage->cboInput->setCurrentIndex(tcpServer->getInput());
        }
    }

    //newTestPage->f_wcPage->tabwc->setCurrentIndex(0);

    newTestPage->btnTest->click();
}

void MainWindow::tcpDsSetup()
{
    if( tcpServer->getCslx() == 0)
    {
        newBwjyPage->beginDsTesting->click();
    }
    else
    {
        newBwjyPage->beginSsTesting->click();
    }

    newBwjyPage->cboBzsz->setCurrentIndex(tcpServer->getBcsz());
    newBwjyPage->combTestingTime->setCurrentIndex(tcpServer->getCsTime());

    newTestPage->btnTest->click();
}

void MainWindow::tcpXbSetup()
{
    newBwjyPage->cboTdh->setCurrentIndex(tcpServer->getTdh());
    newBwjyPage->cboXieboNum->setCurrentIndex(tcpServer->getXbcs());

    bwStart();
}

void MainWindow::tcpMuSetup()
{
//    newBwjyPage->cboInput->setCurrentIndex(tcpServer->getMuInput());
    newBwjyPage->cboTime->setCurrentIndex(tcpServer->getMuTime());

    bwStart();
}

void MainWindow::tcpMnSetup()
{
    newAddPage->txtUn->setText(QString::number( tcpServer->m_fXdyz));
    newAddPage->txtPercent->setText(QString::number( tcpServer->m_fBfd));

    if(tcpServer->haveHarmonic == 1)
    {
        newAddPage->ckboxHarmonic->setChecked(true);
    }
    else
    {
        newAddPage->ckboxHarmonic->setChecked(false);
    }

    QModelIndex index;
    index = newAddPage->tabHarmonic->model()->index(0,1,QModelIndex());
    newAddPage->tabHarmonic->model()->setData(index, tcpServer->h3);

    index = newAddPage->tabHarmonic->model()->index(0,2,QModelIndex());
    newAddPage->tabHarmonic->model()->setData(index, tcpServer->h5);

    index = newAddPage->tabHarmonic->model()->index(0,3,QModelIndex());
    newAddPage->tabHarmonic->model()->setData(index, tcpServer->h7);

    index = newAddPage->tabHarmonic->model()->index(0,4,QModelIndex());
    newAddPage->tabHarmonic->model()->setData(index, tcpServer->h9);

    index = newAddPage->tabHarmonic->model()->index(0,5,QModelIndex());
    newAddPage->tabHarmonic->model()->setData(index, tcpServer->h11);

    newTestPage->btnTest->click();

}
void MainWindow::tcpFt3Setup()
{
    QString s;
    s="3gOK";
    tcpServer->TcpSend(s);
}

void MainWindow::tcpLbSetup()
{
    newLuboPage->combLuboTime->setCurrentIndex(tcpServer->getLbTime());
    qDebug()<<"tcpLbSetup()"<<tcpServer->getLbTime();
    newTestPage->btnTest->click();
}

void MainWindow::changeData()
{
    myDB->getXTCS();
    tbsx=myDB->m_Tbsx;
    newTestPage->cboBctd->setCurrentIndex(myDB->HGQ_Channel);
    newTestPage->txtTestNum->setText(QString::number(myDB->m_Bjcs));
  //  newTestPage->txtYanshi->setText(QString::number(myDB->m_Cyys));
    newTestPage->cboTbfs->setCurrentIndex(myDB->TBFS);
    newTestPage->cboBzSelect->setCurrentIndex(myDB->BZXZ);
    newTestPage->cboBcSelect->setCurrentIndex(myDB->BCXZ);
    newTestPage->txtBzXdy->setText(myDB->bzxdy);
    newTestPage->txtBcXdy->setText(myDB->bcxdy);
    newTestPage->cboCyfs->setCurrentIndex(myDB->m_Cyfs.toInt());

    newTestPage->txtMac->setText(myDB->m_Mac);

    newSysPage->txtSysXs->setText(myDB->sysXs);
    newSysPage->txtSysBc->setText(myDB->sysBc);
    newSysPage->txtSysJc->setText(myDB->sysJc);
    newSysPage->cboDatatime->setCurrentIndex(myDB->m_Tbsx);
    newSysPage->cboSysSf->setCurrentIndex(myDB->m_iSuanfa);
    if(myDB->mCTPT==0)
    {
        newTestPage->cboCTPT->setCurrentIndex(0);
        newTestPage->txtEdyc->setText(myDB->edyc_dl);
    }
    else
    {
     //   newParaPage->rdoPT->setChecked(true);
        newTestPage->cboCTPT->setCurrentIndex(1);
        newTestPage->txtEdyc->setText(myDB->edyc_dy);
    }

    changeset();
    bzselect();
    bcselect();
    changeCyfs();
  //  setparamsg();

    QString sql="select * from muinfo";
    tbWcxx=myDB->openWcxxforSql(sql);
    if (tbWcxx.next())
    {
        APPID=tbWcxx.value(0).toString();
        MAC=tbWcxx.value(1).toString();
        CYPL=tbWcxx.value(2).toString();
        ASDU=tbWcxx.value(3).toString();
    }
    else
    {
        APPID="";
        MAC="";
        CYPL="";
        ASDU="";
    }
    tbWcxx.clear();
    QModelIndex index;
    index=newSysPage->tabMU->model()->index(0,0,QModelIndex());
    newSysPage->tabMU->model()->setData(index,APPID);
    index=newSysPage->tabMU->model()->index(0,1,QModelIndex());
    newSysPage->tabMU->model()->setData(index,MAC);
    index=newSysPage->tabMU->model()->index(0,2,QModelIndex());
    newSysPage->tabMU->model()->setData(index,CYPL);
    index=newSysPage->tabMU->model()->index(0,3,QModelIndex());
    newSysPage->tabMU->model()->setData(index,ASDU);

}

void MainWindow::changeJD(QString type)
{
    QString sql;
    QSqlQuery tempjd;
    sql="select distinct testlevel from testdata where testtype='"+ type +"'";
    tempjd=myDB->openWcxxforSql(sql);
    newTestPage->cboJD->clear();
    while (tempjd.next())
    {
        newTestPage->cboJD->addItem(tempjd.value(0).toString());
    }
    tempjd.clear();
}


void MainWindow::setparamsg()
{
 //   QString smsg="<h2><font size=3 color=red>同步方式:";
    QString smsg="同步方式:";
 //   smsg+=newParaPage->cboTbfs->currentText()+";</font>";
    smsg+=newTestPage->cboTbfs->currentText();
  //  smsg+="<font size=3 color=white>标准:";
    smsg+=";标准:";
    if (newTestPage->cboBzSelect->currentIndex()==4)
        smsg+=newTestPage->txtBzXdy->text()+ "V";
    else
        smsg+=newTestPage->cboBzSelect->currentText();
 //   smsg+=";颜色:白色; </font>";
    smsg+=";颜色:白色";
   // smsg+="<font size=3 color=yellow>被测:";
    smsg+=";被测:";
    if (newTestPage->cboBcSelect->currentIndex()==4)
    {
        smsg+=newTestPage->txtBcXdy->text()+ "V";
    }
    else
    {
        if(guiyue == GuiYue9_1)
            smsg+="光纤 61850-9-1";
        else if(guiyue == GuiYue9_2)
            smsg+="光纤 61850-9-2";
        else
            smsg+=newTestPage->cboBcSelect->currentText();

    }
    if ((newTestPage->cboBcSelect->currentIndex()==5)||(newTestPage->cboBcSelect->currentIndex()==6))
    {
        smsg+=";  被测通道: ";
        smsg+=QString::number(newTestPage->cboBctd->currentIndex()+1);
        newTestPage->labyxz->setText(tr("有效值(%)"));
        if (newTestPage->cboBcSelect->currentIndex()==6)
            smsg+=tr(",颜色:绿色;");
    }
    else
    {
        smsg+=tr(",颜色:绿色;");
        /*
        if (newParaPage->rdoGC->isChecked())
            smsg+=tr(" 算法名称：工程算法(直角坐标系)");
        else
            smsg+=tr(" 算法名称：理论算法(极坐标系)");
        */
        if (newTestPage->cboBzSelect->currentIndex()<=1)
            newTestPage->labyxz->setText(tr("有效值(A)"));
        else
            newTestPage->labyxz->setText(tr("有效值(V)"));
    }
  //  smsg +="</font></h2>";
    newTestPage->labInfo->setText(smsg);
/*
    QString s =tr("单位:");
    if (newParaPage->cboBzSelect->currentIndex()<=1)
        s+="A";
    else
        s+="V";
*/
    QString s=tr("幅值");
    newTestPage->labDw->setText(s.split("", QString::SkipEmptyParts).join("\n"));
}

void MainWindow::bzselect()
{
    if ((newTestPage->cboBzSelect->currentIndex()==4)||(newTestPage->cboBzSelect->currentIndex()==5))
    {
        newTestPage->txtBzXdy->setVisible(true);
        newTestPage->labBzXdy->setVisible(true);
    }
    else
    {
        newTestPage->txtBzXdy->setVisible(false);
        newTestPage->labBzXdy->setVisible(false);
    }
}
void MainWindow::bcselect()
{
    newTestPage->labCyfs->setVisible(false);
    newTestPage->cboCyfs->setVisible(false);
    newTestPage->labMac->setVisible(false);
    newTestPage->txtMac->setVisible(false);
    newTestPage->btnGet->setVisible(false);
    newTestPage->btnAll->setVisible(false);
    newTestPage->labInput->setVisible(false);
    newTestPage->cboInput->setVisible(false);
    if (newTestPage->cboBcSelect->currentIndex()==4)//模拟小电压
    {
        newTestPage->txtBcXdy->setVisible(true);
        newTestPage->labBcXdy->setVisible(true);
        newTestPage->labBctd->setVisible(false);
        newTestPage->cboBctd->setVisible(false);
     //   newParaPage->szlGroup->setVisible(false);
        newTestPage->labBhCl->setVisible(false);
        newTestPage->cboBhCl->setVisible(false);
  //      newParaPage->rdoGC->setVisible(true);
  //      newParaPage->rdoLL->setVisible(true);
    //    newParaPage->cboBcSelect->setMaximumWidth(100);
    }
    else if (newTestPage->cboBcSelect->currentIndex()==5)//数字量
    {
        newTestPage->txtBcXdy->setVisible(false);
        newTestPage->labBcXdy->setVisible(false);
        newTestPage->labBctd->setVisible(true);
        newTestPage->cboBctd->setVisible(true);
        newTestPage->labBhCl->setVisible(false);
        newTestPage->cboBhCl->setVisible(false);

        newTestPage->labCyfs->setVisible(true);
        newTestPage->cboCyfs->setVisible(true);
//        newTestPage->labInput->setVisible(true);
//        newTestPage->cboInput->setVisible(true);

   //     newTestPage->labMac->setVisible(true);
   //     newTestPage->txtMac->setVisible(true);
   //     newTestPage->btnGet->setVisible(true);
        newTestPage->btnAll->setVisible(true);
    }
    else if (newTestPage->cboBcSelect->currentIndex()==6)//FT3
    {
        newTestPage->txtBcXdy->setVisible(false);
        newTestPage->labBcXdy->setVisible(false);
        newTestPage->labBctd->setVisible(true);
        newTestPage->cboBctd->setVisible(true);
        newTestPage->labBhCl->setVisible(true);
        newTestPage->cboBhCl->setVisible(true);
    }
    else
    {
        newTestPage->txtBcXdy->setVisible(false);
        newTestPage->labBcXdy->setVisible(false);
        newTestPage->labBctd->setVisible(false);
        newTestPage->cboBctd->setVisible(false);
        newTestPage->labBhCl->setVisible(false);
        newTestPage->cboBhCl->setVisible(false);
    }
}
void MainWindow::changeSaveFlag()
{
    if (newTestPage->cboSave->currentIndex()==0)
    {
    //    newTestPage->labNum->setVisible(true);
        newTestPage->txtTestNum->setVisible(true);
     //   newTestPage->labYanshi->setVisible(false);
    //    newTestPage->txtYanshi->setVisible(false);
    //    newTestPage->labYanshiDw->setVisible(false);
    }
    else if (newTestPage->cboSave->currentIndex()==1)
    {
  //      newTestPage->labNum->setVisible(true);
        newTestPage->txtTestNum->setVisible(true);
    //    newTestPage->labYanshi->setVisible(true);
    //    newTestPage->txtYanshi->setVisible(true);
    //    newTestPage->labYanshiDw->setVisible(true);
    }
}
void MainWindow::changeset()
{
    if (newTestPage->cboCTPT->currentIndex()==0)
    {
     //   newTestPage->labYc->setText(tr("额定一次电流"));
        newTestPage->txtEdyc->setText(myDB->edyc_dl);
      //  newParaPage->labYcdw->setText(tr("A"));
        newTestPage->cboEdycDw->clear();
        newTestPage->cboEdycDw->setMinimumWidth(50);
        newTestPage->cboEdycDw->addItem(tr("A"));
        changeJD("I");
        if (myDB->m_CTJD=="")
            newTestPage->cboJD->setCurrentIndex(1);
        else
        {
            for(int i=0;i<newTestPage->cboJD->count();i++)
            {
                newTestPage->cboJD->setCurrentIndex(i);
                if (newTestPage->cboJD->currentText()==myDB->m_CTJD)
                    break;
            }
        }
    }
    else if (newTestPage->cboCTPT->currentIndex()==1)
    {
   //     newTestPage->labYc->setText(tr("额定一次电压"));
        newTestPage->txtEdyc->setText(myDB->edyc_dy);
      //  newParaPage->labYcdw->setText(tr("/√3kV"));
        newTestPage->cboEdycDw->clear();
        newTestPage->cboEdycDw->setMinimumWidth(100);
        newTestPage->cboEdycDw->addItem(tr("kV"));
        newTestPage->cboEdycDw->addItem(tr("/√3kV"));
        newTestPage->cboEdycDw->setCurrentIndex(1);
        changeJD("U");
        if (myDB->m_PTJD=="")
            newTestPage->cboJD->setCurrentIndex(1);
        else
        {
            for(int i=0;i<newTestPage->cboJD->count();i++)
            {
                newTestPage->cboJD->setCurrentIndex(i);
                if (newTestPage->cboJD->currentText()==myDB->m_PTJD)
                    break;
            }
        }
    }
}

void MainWindow::slotBtnTest()
{
    saveCfg();

    nowtest = newTestPage->tabwc->currentIndex();

    if (nowtest==0)   //误差测量
    {
        paraOK();
    }
    else if(nowtest ==1)//LM 非同步测量
    {
        if (newTestPage->btnTest->text()=="停止")
        {
            newTestPage->btnTest->setText(tr("开始"));
            f_paraReturn();
            return;
        }

        if(!m_clnp->isOpen())
        {
            qDebug()<<"SlotBtnTest(), Try to open smv port!";

            QString sNetPortDescription=NETDEV;
            if ( m_clnp->openNetDev(sNetPortDescription,&errBuf))
            {
               // openNetFlag = false;
                myHelper::ShowMessageBoxError(tr("网口打开错误, 没有权限或者网口不存在！"));

                return;
            }
        }
        //            openNetFlag=false;
        //            openNetTimer->stop();

        qDebug()<<"SlotBtnTest(), paraOk! Ready to do test!";

        f_paraOK();
        //开始捕获一个数据包
        //被测选择序号 0:9-2,1:9-2LE  2: FT3
        //m_clnp->recvThread->m_BcSelect_Index = newTestPage->f_wcPage->cboBcSelect->currentIndex() ;
        qDebug()<<"SlotBtnTest(), Start_CapPcaket()";
        m_clnp->Start_CapPcaket();

        fakePPS->start(200);

        fake_pps_count = 0;

        //记录MU 延时
        //if(newTestPage->f_wcPage->cboBcSelect->currentIndex() ==5)// 9-2LE的时候替换
        //{
        //  QString s_muys = QString::number(m_clnp->recvThread->m_MUYSTime_Value);
        //  newTestPage->f_wcPage->txtMUYS->setText(s_muys);
        //}

        //            newTestPage->f_wcPage->btnTest->setText(tr("停止"));
        newTestPage->btnTest->setText(tr("停止"));
        newTestPage->btnAll->setVisible(true);


    }//LM 非同步测量
    else if (nowtest==3)   //加量输出
    {
        addLiang();
    }
    else if (nowtest==4)   //录波
    {
        StartLuBo();
    }
    else if (nowtest==5)   //MU检测
    {
        bwStart();
    }
}

void MainWindow::addLiang()
{
    if (sourceIsActive)
    {
        sourceIsActive = false;
        newTestPage->btnTest->setText("升源");

        QByteArray setSourceZero(8,0x00);
        setSourceZero[0]=0xaa;

        qDebug()<<"set source to zero"<<setSourceZero.toHex();

        serialCmd(setSourceZero);

        udpOrder(0);

        return;
    }

    sourceIsActive = true;
    newTestPage->btnTest->setText("降源");

    if (newAddPage->rdoMn->isChecked())
    {
        newAddPage->analogCmd();

        serialCmd(newAddPage->cmdToDA);

        udpOrder(0);
    }
    else
    {
        udpOrder('b');
    }
}
void MainWindow::serialCmd(const QByteArray &data)
{
    if(serial == NULL) serial = new QSerialPort(this);

    if ( serial->isOpen() == false )
    {
        // serial->setPortName("/dev/ttyUSB0"); // set the port name
        serial->setPortName("\\\\.\\COM4");
        serial->setBaudRate(9600);
        serial->setDataBits(QSerialPort::Data8);
        serial->setParity(QSerialPort::NoParity);
        serial->setStopBits(QSerialPort::OneStop);
        serial->setFlowControl(QSerialPort::NoFlowControl);


        if( serial->open(QIODevice::ReadWrite ) == false)
        {
           myHelper::ShowMessageBoxError(tr("打开串口错误: ")+serial->errorString());
        }
    }

    if  (serial->isOpen())
    {
        serial->write(data);

        labInfo->setText("                 指令已发送，请稍侯！");
        widgetInfo->show();
        showInfoTimer->start(2000);
    }
}
void MainWindow::paraOK()
{
    if (newTestPage->btnTest->text()=="停止")
    {
        newTestPage->btnTest->setText(tr("开始"));
        paraReturn();
        return;
    }
 //   QPainter painter(newTestPage->widget);
 //   newTestPage->widget->repaint();
 //   newTestPage->tabwc->setEnabled(false);
  //  newTestPage->btnSave->setEnabled(true);
    tDataProcess->init();
    tDataProcess->setBiJiaoCiShu(newTestPage->txtTestNum->text().toInt());
    if (newTestPage->cboCTPT->currentIndex()==0)
    {
        tDataProcess->setTestType("I",newTestPage->cboJD->currentText());
        myDB->setCTJD(newTestPage->cboJD->currentText());
    }
    else if(newTestPage->cboCTPT->currentIndex()==1)
    {
        tDataProcess->setTestType("U",newTestPage->cboJD->currentText());
        myDB->setPTJD(newTestPage->cboJD->currentText());
    }


    if(((newTestPage->cboBzSelect->currentText()=="5A")&&(newTestPage->cboBcSelect->currentText()=="1A"))||
      (((newTestPage->cboBzSelect->currentText()=="1A")&&(newTestPage->cboBcSelect->currentText()=="5A"))))
    {
       // QMessageBox::information(NULL,"测量参数选择","标准与被测参数不符合要求，不能进行测量！");
        myHelper::ShowMessageBoxInfo(tr("标准与被测参数不符合要求，不能进行测量！"));
        return;
    }
    initTest();

    QString xz=QString::number(newTestPage->cboBzSelect->currentIndex()) + QString::number(newTestPage->cboBcSelect->currentIndex());
    if (xz=="35")
        xz="25";
    if (xz=="34")
        xz="24";
        
    if (xz=="26" || xz=="36")
        xz="25";
    if (xz=="06")
        xz="05";
    if (xz=="16")
        xz="15";
    if (xz=="46")
        xz="45";

    if(newTestPage->harmonicChoose != 1)
    {
        labInfo->setText("谐波误差测试，谐波次数 = "+QString::number(newTestPage->harmonicChoose));
        widgetInfo->setVisible(true);
        showInfoTimer->start(3000);

        udp->harmonicOrder = newTestPage->harmonicChoose;
        cappacket->harmonicOrder = newTestPage->harmonicChoose;
    }
    else
    {
        udp->harmonicOrder = 1;
        cappacket->harmonicOrder = 1;
    }

    QSqlQuery tbWcbc=myDB->openWcxxforSql("select * from wcbc where type='"+xz +"'");
    if (tbWcbc.next())
    {
        bcdata[1]=tbWcbc.value(1).toDouble();
        jcdata[1]=tbWcbc.value(2).toDouble();
        bcdata[2]=tbWcbc.value(3).toDouble();
        jcdata[2]=tbWcbc.value(4).toDouble();
        bcdata[3]=tbWcbc.value(5).toDouble();
        jcdata[3]=tbWcbc.value(6).toDouble();
        bcdata[0]=tbWcbc.value(7).toDouble();
        jcdata[0]=tbWcbc.value(8).toDouble();
    }
    tbWcbc.clear();
    myDB->setHGQ_Channel(newTestPage->cboBctd->currentIndex()+1);
    myDB->setTBFS(newTestPage->cboTbfs->currentIndex());
    myDB->setBZXZ(newTestPage->cboBzSelect->currentIndex());
    myDB->setBCXZ(newTestPage->cboBcSelect->currentIndex());
    myDB->setBZXDY(newTestPage->txtBzXdy->text());
    myDB->setBCXDY(newTestPage->txtBcXdy->text());
    myDB->setBjcs(newTestPage->txtTestNum->text().toInt());
    myDB->setSuanfa(newSysPage->cboSysSf->currentIndex());
  //  myDB->setCyys(newTestPage->txtYanshi->text().toInt());
    if(newTestPage->cboCTPT->currentIndex()==0)
        myDB->setCTPT(0);
    else
        myDB->setCTPT(1);
    myDB->setEDYC(newTestPage->txtEdyc->text());
    int icyfs=newTestPage->cboCyfs->currentIndex();
    myDB->setCyfs(QString::number(icyfs));
    MAC=newTestPage->txtMac->text();
    myDB->setMac(newTestPage->txtMac->text());
    myDB->setXTCS();
    saveMuinfo();           //保存mac地址等信息

  //  QString sInfo="";
//    setparamsg();   //显示测量信息
    if (newTestPage->txtTestNum->text().isEmpty())
        m_iAvgNum=0;
    else
        m_iAvgNum=newTestPage->txtTestNum->text().toInt();
    m_iBiJiaoCiShu = m_iAvgNum;
  //  pagesWidget->setCurrentIndex(7);//测量界面统一为一个界面
    setTestText(0);
    if(newTestPage->cboBzSelect->currentIndex()==0)
        bzTestXs=5;
    else if (newTestPage->cboBzSelect->currentIndex()==1)
        bzTestXs=1;
    else if (newTestPage->cboBzSelect->currentIndex()==2)
        bzTestXs=100;
    else if (newTestPage->cboBzSelect->currentIndex()==3)
        bzTestXs=57.73505;
    else
        bzTestXs=newTestPage->txtBzXdy->text().toFloat();

    if(newTestPage->cboBcSelect->currentIndex()==0)
        bcTestXs=5;
    else if (newTestPage->cboBcSelect->currentIndex()==1)
        bcTestXs=1;
    else if (newTestPage->cboBcSelect->currentIndex()==2)
        bcTestXs=100;
    else if (newTestPage->cboBcSelect->currentIndex()==3)
        bcTestXs=57.73505;
    else if (newTestPage->cboBcSelect->currentIndex()==4)
        bcTestXs=newTestPage->txtBcXdy->text().toFloat();
    else                //暂时为11585,如果为9-2则另外设置
        bcTestXs=11585;

    newTestPage->btnTest->setText(tr("停止"));
    isTested=true;
    if(newTestPage->cboBcSelect->currentIndex()==5)
    {
        btnFlag=11;

        clfs=1;
        if (newTestPage->cboBzSelect->currentIndex()==5)
            cappacket->setTestSelect(1);
        else
            cappacket->setTestSelect(0);
   //     cappacket->setXieboNum(newTestPage->cboXbcs->currentText().toInt());

        if (newSysPage->cboSysSf->currentIndex()==1)
        {
       //     cappacket->setSuanFa(1);
            cappacket->setSuanFa(2);
        }
        else
        {
            cappacket->setSuanFa(0);
        }
    //    if (newSysPage->BLDG)
    //        cappacket->setSuanFa(2);


     //   cappacket->setSuanFa(0);
        /*
        int iTongDaoHao=newTestPage->cboBctd->currentText().toInt();
        int iChannel=iTongDaoHao;
        int imChannel = iChannel % 12;
        int icChannel = iChannel / 12;
        */
/*
        QModelIndex index;
        for(int i=1;i<13;i++)
        {
            index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
            if (imChannel==0)
                newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
            else
                newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
        }
        */
      //  newTestPage->tabTd->setVisible(true);
      //  newTestPage->rdoAlltd->setVisible(true);
     //   newTestPage->rdoCltd->setVisible(true);
        newTestPage->labSync->setText("");
    //    newTestPage->labSyncPng->setVisible(true);

        captimer->start(100);

        fakePPS->start(200);

        fake_pps_count = 0;
    }
    else if(newTestPage->cboBcSelect->currentIndex()==6)            //Ft3
    {        
        btnFlag=12;

        udp->setCTPT(newTestPage->cboCTPT->currentIndex());
        udp->setFT3lx(newTestPage->cboBhCl->currentIndex());

        clfs=2;
    }
    else
    {
        iTestMode=0;
        btnFlag=13;

        clfs=0;
   //     newTestPage->tabTd->setVisible(false);
   //     newTestPage->rdoAlltd->setVisible(false);
   //     newTestPage->rdoCltd->setVisible(false);
        newTestPage->labSync->setText("");
    //    newTestPage->labSyncPng->setVisible(false);
    }
    int ilen=newTestPage->getStructLen();
    cUdpSend=(char*)malloc(ilen);
    newTestPage->getsendUdp(cUdpSend,2);   //正常测量命令
    m_iFuwei=1;
    if (newSysPage->cboSysSf->currentIndex()==1)
        udp->setSuanFa(2);
    else
        udp->setSuanFa(0);
    udp->UdpSendByte(cUdpSend,ilen);
  //  udp->setFuZhi(bzTestXs);
 //   udp->setFuZhi_bc(bcTestXs);
    udpTimer->start(3000);
    udp->setRead(true);
    newTestPage->labSyncPng->setVisible(false);
    isSaved=true;
    nowXh="";
    preBFD="";

    setTestSelect(false);
}

void MainWindow::slotUdp()
{
    if (udp->getSt())
    {
        free(cUdpSend);
        udp->setSt(false);
        udpTimer->stop();
        qDebug()<<"end";
       // QPixmap pixmap("images/bj-1.jpg");
      //  QIcon icon;
      //  icon.addPixmap(pixmap);
      //  btnParaTest->setIcon(icon);
        if (m_iFuwei==0)
        {
            udp->setRead(false);
            newTestPage->labSyncPng->setVisible(false);
        }
        else
        {
          //  newTestPage->labSyncPng->setPixmap(QPixmap(":images/tb.png"));
            newTestPage->labSyncPng->setStyleSheet("color:rgb(255,0,0);");
            newTestPage->labSyncPng->setVisible(true);
        }
    }
    else
    {
        if (udpResendNum==1)
        {
            udp->setSt(false);
            udpTimer->stop();
            return;
        }
        int ilen=newTestPage->getStructLen();
        udp->UdpSendByte(cUdpSend,ilen);
     //   newTestPage->labSyncPng->setPixmap(QPixmap(":images/wtb.png"));
        newTestPage->labSyncPng->setStyleSheet("color:rgb(0,255,0);");
        newTestPage->labSyncPng->setVisible(true);
        qDebug()<<"reSend";
    }
    udpResendNum++;
}

void MainWindow::slotTestEnd()
{
    double bfd,bc,jc;

    if (newTestPage->cboSave->currentIndex()==0)   //如果是手动存储则退出
        return;

    wcbjWidget->setGeometry(380,180,250,200);

    bfd=newTestPage->txtBFB->text().toDouble();
    bc=newTestPage->txtBc->text().toDouble();
    jc=newTestPage->txtJc->text().toDouble();

    bool isOK=tDataProcess->ProcessData(bfd);

    if (isOK)  //显示
    {
        yanshiNum++;

        tDataProcess->setCyFlag(true);
        wcbjWidget->setVisible(true);
        if (tDataProcess->getTestPointOver())
        {
            QString info="数据已存储！";
            tDataProcess->setTestPointOver(false);
            tDataProcess->setCyFlag(false);
            testnum=0;
            yanshiNum=0;
            modela->setRowCount(0);
            wcbjWidget->setVisible(false);
            saveWcdata();
         //   labInfo->setText(info);
            showInfoTimer->start(2000);
            if (tDataProcess->getTestOver())
            {
                info="全部测量完成！";
           //     labInfo->setText(info);
            }
            return;
        }
        testnum++;
        QStandardItem* item0=new QStandardItem();
        item0->setTextAlignment(Qt::AlignCenter);
        item0->setText(QString::number(testnum));
        QStandardItem* item1=new QStandardItem();
        item1->setTextAlignment(Qt::AlignCenter);
        item1->setText(QString::number(bc,'f',4));
        QStandardItem* item2=new QStandardItem();
        item2->setTextAlignment(Qt::AlignCenter);
        item2->setText(QString::number(jc,'f',2));
        QList<QStandardItem*> item;
        item << item0<< item1<< item2;
        modela->appendRow(item);
        tabWcbj->setModel(modela);
        int maxValue=tabWcbj->verticalScrollBar()->maximum();
        int nowValue=tabWcbj->verticalScrollBar()->value();
        if (nowValue<maxValue)
            tabWcbj->verticalScrollBar()->setSliderPosition(maxValue);
    }
}

QString MainWindow::formatString(QString s)
{
    QString str="";
    int n=s.length();
    int js=0;
    for(int i=n-1;i>=0;i--)
    {
        if (s.mid(i,1)=="0")
            js++;
        else
            break;
    }
    str=s.mid(0,n-js);
    if (str.mid(str.length()-1,1)==".")
        str=str.mid(0,str.length()-1);
    return str;
}
void MainWindow::setCSCS()
{
  //  int iTongDaoHao=newParaPage->cboBctd->currentText().toInt();
    int iCltd=newTestPage->cboBctd->currentText().toInt();
    /*
    int iChannel=iCltd;

    int imChannel = iChannel % 12;
    int icChannel = iChannel / 12;
    for(int i=1;i<13;i++)
    {
        QModelIndex index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
        if (imChannel==0)
            newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
        else
            newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
    }

*/
  //  if (!isTested)
  //      return;
    guiyue=cappacket->GuiYueType();
    setparamsg();
    if(guiyue == GuiYue9_1)
    {
        dblFuZhi_HGQ = 11585;
    }
    else if(guiyue == GuiYue9_2)
    {
        if(newTestPage->cboCTPT->currentIndex()==0)		// 如果是CT测量
            dblFuZhi_HGQ = myDB->edyc_dl.toInt() * 1000;
        else
        {
            if (newTestPage->cboEdycDw->currentIndex()==0)
                dblFuZhi_HGQ = myDB->edyc_dy.toDouble() * 100000;
            else
                dblFuZhi_HGQ = myDB->edyc_dy.toDouble()/1.73205 * 100000;
        }
    }
    if (iTestMode==3)    //全帧解析
        cappacket->SetCapParamater(TestChannel_LuBo,1,0,dblFuZhi_HGQ);//通道，周期,起始位,幅值
    else
        cappacket->SetCapParamater(iCltd-1,m_zqgs,0,dblFuZhi_HGQ);//通道，周期,起始位,幅值
    cappacket->setTestChannel(iCltd-1);
    tdSelect();
}

void MainWindow::sigBeginSync(int iFlag)
{
    emit sigSyncSet(iFlag);
}

void MainWindow::slotSyncSet(int iFlag)
{
    if(guiyue == GuiYue9_1)
    {
        newTestPage->labSync->setText("");
   //     newTestPage->labSyncPng->setVisible(false);
    }
    else if(guiyue == GuiYue9_2)
    {
        if (iFlag==0)
        {
            newTestPage->labSync->setText("未同步");
            newTestPage->labSync->setStyleSheet("color:rgb(250,255,0);");
        //    newTestPage->labSyncPng->setPixmap(QPixmap(":images/wtb.png"));
        //    newTestPage->labSyncPng->setVisible(true);
        }
        else if (iFlag==1)
        {
            newTestPage->labSync->setText("已同步");
            newTestPage->labSync->setStyleSheet("color:rgb(0,255,0);");
        //    newTestPage->labSyncPng->setPixmap(QPixmap(":images/tb.png"));
       //     newTestPage->labSyncPng->setVisible(true);
        }
    }
}

void MainWindow::NetTest()
{
    qDebug()<<"NetTest is called!";

   if(nowtest==0)//同步误差测量
   {
       m_zqgs=iZHOUQI;
       iTestMode=0;    //误差测量
       captimer->stop();
       bStart=false;
       guiyue="";
       netYouXiaoZhi=0;
       netXiangWei=0;

     //  bool allOK=true;
       openNetFlag=true;
       if (!cappacket->IsOpen())
       {
            cappacket->StopCap(false);
            openNetFlag=cappacket->Open(newTestPage->cboCyfs->currentIndex());
            openNetTimer->start(1000);
       }

        if (openNetFlag)
        {
            openNetFlag=false;
            openNetTimer->stop();
            setCSCS();
            initTest();
            cappacket->setTestType(0);
            cappacket->StopCap(false);
            cappacket->setMacGl(newTestPage->cboCyfs->currentIndex());
            cappacket->start();//打开网口
            timer->start( 1000 );

            isSaved=true;
            nowXh="";
            preBFD="";
            newTestPage->btnTest->setText(tr("停止"));
            newTestPage->btnAll->setVisible(true);
        }
        else
        {
            newTestPage->btnTest->setText(tr("开始"));
            newTestPage->btnAll->setVisible(false);
            isTested=false;
            udp->setRead(false);
            setTestText(0);
            udpTimer->stop();
            udp->setRead(false);
            paraReturn();
         //   QMessageBox::information(NULL,tr("初始化结果"),tr("初始化失败！"));
            myHelper::ShowMessageBoxError(tr("未检测到 9-2 数据，请检查MAC设置或连线！"));
        }
   }
   else if(nowtest ==1)//LM 非同步误差测量
   {
       m_zqgs=iZHOUQI;
       iTestMode=0;    //非同步误差测量
       captimer->stop();
       bStart=false;
       guiyue="";
       netYouXiaoZhi=0;
       netXiangWei=0;
       isSaved=true;
       nowXh="";
       preBFD="";
       f_setCSCS();
       initTest();
       m_clnp->recvThread->setTestType(0);

       //m_clnp->Start_run();
       m_clnp->recvThread->start();

   }
}

void MainWindow::sysOK()
{
    myDB->setHGQ_Channel(newTestPage->cboBctd->currentIndex()+1);
  //  myDB->setSmpRate92(newSysPage->spiBCCYSL->text().toInt());
  //  myDB->setSmpRate92(newSysPage->txtBCCYSL->text().toInt());
    myDB->setTbsx(newSysPage->cboDatatime->currentIndex());
    myDB->setSysXs(newSysPage->txtSysXs->text());
    myDB->setSysBc(newSysPage->txtSysBc->text());
    myDB->setSysJc(newSysPage->txtSysJc->text());
    tbsx=newSysPage->cboDatatime->currentIndex();
 //   myDB->setrepeat(ui->spirepeat->text().toInt());
 //   myDB->setbfbzero(ui->spibfb->text());
 //   myDB->setBCBC(ui->txtBCbc->text().toDouble());
 //   myDB->setJCBC(ui->txtJCbc->text().toDouble());
    if(newSysPage->tabWidget->currentIndex()==1)
    {

    if((newTestPage->cboBzSelect->currentIndex()==0)&&(newTestPage->cboBcSelect->currentIndex()==4))
    {
        myDB->setsystemBC(1,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    else if((newTestPage->cboBzSelect->currentIndex()==1)&&(newTestPage->cboBcSelect->currentIndex()==4))
    {
        myDB->setsystemBC(2,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    else if(((newTestPage->cboBzSelect->currentIndex()==2)||(newTestPage->cboBzSelect->currentIndex()==3))&&(newTestPage->cboBcSelect->currentIndex()==4))
    {
        myDB->setsystemBC(3,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    else if((newTestPage->cboBzSelect->currentIndex()==4)&&(newTestPage->cboBcSelect->currentIndex()==4))
    {
        myDB->setsystemBC(4,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    else if((newTestPage->cboBzSelect->currentIndex()==0)&&(newTestPage->cboBcSelect->currentIndex()==0))
    {
        myDB->setsystemBC(8,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    else if((newTestPage->cboBzSelect->currentIndex()==1)&&(newTestPage->cboBcSelect->currentIndex()==1))
    {
        myDB->setsystemBC(9,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    else if(newTestPage->cboBcSelect->currentIndex()==5)
    {
        if (newTestPage->cboBzSelect->currentIndex()==0)
            myDB->setsystemBC(5,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
        else if (newTestPage->cboBzSelect->currentIndex()==1)
            myDB->setsystemBC(6,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
        else if ((newTestPage->cboBzSelect->currentIndex()==2)||(newTestPage->cboBzSelect->currentIndex()==3))
            myDB->setsystemBC(7,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
        else
            myDB->setsystemBC(0,newSysPage->txtBcbc->text().toDouble(),newSysPage->txtJcbc->text().toDouble());
    }
    }
    myDB->setXTCS();
    paraReturn();

}

void MainWindow::sysCancel()
{
    changeData();
    paraReturn();
}
void MainWindow::sysmanager()
{
    if(newSysPage->txtMima->text()=="88888888")
    {
     //   newSysPage->btnSysOk->setVisible(true);
        newSysPage->labMima->setVisible(false);
        newSysPage->txtMima->setVisible(false);
        newSysPage->btnEnter->setVisible(false);
     //   newSysPage->labBcbc->setText(tr("修改后请按保存"));
     //   newSysPage->labBcbc->setVisible(true);
     //   newSysPage->labJcbc->setVisible(true);
      //  newSysPage->txtBcbc->setVisible(true);
    //    newSysPage->txtJcbc->setVisible(true);
        newSysPage->tabSys->setCurrentIndex(0);
        newSysPage->tabSys->setVisible(true);
        newSysPage->btnSysSave->setVisible(true);


        QString bzbc=QString::number(newTestPage->cboBzSelect->currentIndex());
        bzbc +=QString::number(newTestPage->cboBcSelect->currentIndex());
        if (bzbc=="35")
            bzbc="25";
        if (bzbc=="34")
            bzbc="24";
        if (bzbc=="00")
            newSysPage->cboBzbc->setCurrentIndex(0);
        else if (bzbc=="11")
            newSysPage->cboBzbc->setCurrentIndex(1);
        else if (bzbc=="04")
            newSysPage->cboBzbc->setCurrentIndex(2);
        else if (bzbc=="14")
            newSysPage->cboBzbc->setCurrentIndex(3);
        else if (bzbc=="24")
            newSysPage->cboBzbc->setCurrentIndex(4);
        else if (bzbc=="44")
            newSysPage->cboBzbc->setCurrentIndex(5);
        else if (bzbc=="05")
            newSysPage->cboBzbc->setCurrentIndex(6);
        else if (bzbc=="15")
            newSysPage->cboBzbc->setCurrentIndex(7);
        else if (bzbc=="25")
            newSysPage->cboBzbc->setCurrentIndex(8);
        else if (bzbc=="45")
            newSysPage->cboBzbc->setCurrentIndex(9);
        else if (bzbc=="22")
            newSysPage->cboBzbc->setCurrentIndex(10);
        else if (bzbc=="33")
            newSysPage->cboBzbc->setCurrentIndex(11);

        systemLoad(bzbc);
        btnFlag=511;
    }
    else
    {
     //   QMessageBox::information (NULL,"提示","密码不正确！");
        myHelper::ShowMessageBoxError(tr("密码不正确！"));
        newSysPage->txtMima->setText("");
        newSysPage->txtMima->setFocus();
    }
}
void MainWindow::systemLoad(QString bz)
{
 //   QSqlQuery tbWcbc=myDB->openWcxxforSql("");
    /*
    while (tbWcbc.next())
    {
        QStandardItem* item0=new QStandardItem();
        QStandardItem* item11=new QStandardItem();
        QStandardItem* item21=new QStandardItem();
        QStandardItem* item31=new QStandardItem();
        QStandardItem* item12=new QStandardItem();
        QStandardItem* item22=new QStandardItem();
        QStandardItem* item32=new QStandardItem();
        if (tbWcbc.value(0).toString()=="00")
            item0->setText(tr("5A-5A"));
        else if (tbWcbc.value(0).toString()=="11")
            item0->setText(tr("1A-1A"));
        else if (tbWcbc.value(0).toString()=="04")
            item0->setText(tr("5A-模拟小电压"));
        else if (tbWcbc.value(0).toString()=="14")
            item0->setText(tr("1A-模拟小电压"));
        else if (tbWcbc.value(0).toString()=="24")
            item0->setText(tr("100V或100/√3V-模拟小电压"));
        else if (tbWcbc.value(0).toString()=="44")
            item0->setText(tr("模拟小电压-模拟小电压"));
        else if (tbWcbc.value(0).toString()=="05")
            item0->setText(tr("5A-数字量"));
        else if (tbWcbc.value(0).toString()=="15")
            item0->setText(tr("1A-数字量"));
        else if (tbWcbc.value(0).toString()=="25")
            item0->setText(tr("100V或100/√3V-数字量"));
        else if (tbWcbc.value(0).toString()=="45")
            item0->setText(tr("模拟小电压-数字量"));
        item11->setText(tbWcbc.value(1).toString());
        item12->setText(tbWcbc.value(2).toString());
        item21->setText(tbWcbc.value(3).toString());
        item22->setText(tbWcbc.value(4).toString());
        item31->setText(tbWcbc.value(5).toString());
        item32->setText(tbWcbc.value(6).toString());
        QList<QStandardItem*> item;
        item << item0 << item11 << item12 << item21 << item22 << item31 << item32;
        newSysPage->model->appendRow(item);
    }
    newSysPage->tabCsbc->setModel(newSysPage->model);
    */
    QSqlQuery tbWcbc=myDB->openWcxxforSql("select * from wcbc where type='"+ bz +"'");
    if (tbWcbc.next())
    {
        newSysPage->txtbc->setText(tbWcbc.value(7).toString());
        newSysPage->txtjc->setText(tbWcbc.value(8).toString());
        newSysPage->txtbc1->setText(tbWcbc.value(1).toString());
        newSysPage->txtjc1->setText(tbWcbc.value(2).toString());
        newSysPage->txtbc2->setText(tbWcbc.value(3).toString());
        newSysPage->txtjc2->setText(tbWcbc.value(4).toString());
        newSysPage->txtbc3->setText(tbWcbc.value(5).toString());
        newSysPage->txtjc3->setText(tbWcbc.value(6).toString());
    }
    else
    {
        newSysPage->txtbc->setText("0");
        newSysPage->txtjc->setText("0");
        newSysPage->txtbc1->setText("0");
        newSysPage->txtjc1->setText("0");
        newSysPage->txtbc2->setText("0");
        newSysPage->txtjc2->setText("0");
        newSysPage->txtbc3->setText("0");
        newSysPage->txtjc3->setText("0");
    }
    tbWcbc.clear();
}

void MainWindow::tabchanged()
{
  //  sysList->setVisible(false);
    if(newSysPage->tabWidget->currentIndex()==0)
    {
        newSysPage->labMima->setVisible(true);
        newSysPage->txtMima->setVisible(true);
        newSysPage->labBcbc->setText("");
        newSysPage->txtBcbc->setVisible(false);
        newSysPage->btnBc->setVisible(false);
        newSysPage->btnEnter->setVisible(true);
     //   newSysPage->labBcbc->setVisible(false);
        newSysPage->labJcbc->setVisible(false);
        newSysPage->txtBcbc->setVisible(false);
        newSysPage->txtJcbc->setVisible(false);
        newSysPage->tabSys->setVisible(false);
        newSysPage->btnSysSave->setVisible(false);
        newSysPage->txtMima->setText("");
        newSysPage->txtMima->setFocus();

        btnFlag=51;
    }

    else if(newSysPage->tabWidget->currentIndex()==1)
    {
        btnFlag=52;
    }
}
void MainWindow::clearFocusAll()
{
    if (focusIn==0)
        newTestPage->txtBzXdy->clearFocus();
    else if (focusIn==1)
        newTestPage->txtBcXdy->clearFocus();
    else if(focusIn==2)
        newTestPage->txtEdyc->clearFocus();
 //   else if(focusIn==3)
 //       newTestPage->txtXbYxz->clearFocus();
    else if (focusIn==4)
        newSysPage->txtMima->clearFocus();
    else if (focusIn==5)
        newLuboPage->txtLuboTime->clearFocus();
    else if (focusIn==6)
        newSysPage->txtSysXs->clearFocus();
    else if (focusIn==7)
        newSysPage->txtSysBc->clearFocus();
    else if (focusIn==8)
        newSysPage->txtSysJc->clearFocus();
    else if (focusIn==9)
        txtXh->clearFocus();
    else if (focusIn==10)
        txtSj->clearFocus();
    else if (focusIn==11)
        newTestPage->txtTestNum->clearFocus();

    else if ((focusIn==15) ||(focusIn==14)||(focusIn==13))
    {
        if (newAddPage->rdoMn->isChecked())
            newAddPage->rdoMn->setFocus();
        else if (newAddPage->rdoFt3->isChecked())
            newAddPage->rdoFt3->setFocus();//Qt::FocusPolicy
    }
    else if(focusIn==16)
    {
        newAddPage->rdoMn->setFocus();
    }
    else if (focusIn==20)
        newSysPage->txtbc->clearFocus();
    else if (focusIn==21)
        newSysPage->txtbc1->clearFocus();
    else if (focusIn==22)
        newSysPage->txtbc2->clearFocus();
    else if (focusIn==23)
        newSysPage->txtbc3->clearFocus();
    else if (focusIn==24)
        newSysPage->txtjc->clearFocus();
    else if (focusIn==25)
        newSysPage->txtjc1->clearFocus();
    else if (focusIn==26)
        newSysPage->txtjc2->clearFocus();
    else if (focusIn==27)
        newSysPage->txtjc3->clearFocus();
    else if (focusIn==28)
        newAddPage->txtUn->clearFocus();
    else if (focusIn==29)
        newAddPage->txtPercent->clearFocus();
    else if (focusIn==30)
        newTestPage->f_wcPage->txtBzXdy->clearFocus();
    else if (focusIn==31)
        newTestPage->f_wcPage->txtBcXdy->clearFocus();
    else if(focusIn==32)
        newTestPage->f_wcPage->txtEdyc->clearFocus();
    else if (focusIn==33)
        newTestPage->f_wcPage->txtTestNum->clearFocus();
    else if(focusIn == 34)
        newTestPage->f_wcPage->txtMUYS->clearFocus();
  //  else if(focusIn==12)
  //      newTestPage->txtYanshi->clearFocus();


}
bool MainWindow::eventFilter(QObject *watched, QEvent *e)
{
    if (iTestMode==0)
    {
        if(newTestPage->tabwc->currentIndex() ==1)//非同步误差测量
        {
            if(watched ==newTestPage->widget)
            {
                if (e->type() == QEvent::Paint)
                {
                    f_paintOnUdp(newTestPage->widget);
                    return true;
                }
            }

        }
        else
        {
            if(watched ==newTestPage->widget)
            {
                if (e->type() == QEvent::Paint)
                {
                    paintOnUdp(newTestPage->widget);
                    return true;
                }
            }
        }

    }
    else if (iTestMode==2)
    {
        if (watched ==newTestPage->widget)
        {
            if (e->type() == QEvent::Paint)
            {
                qDebug()<<"paint lubo!";

                paintOnLubo(newTestPage->widget);

                return true;
            }
        }
    }
    else if (iTestMode==3)
    {
        if(newTestPage->tabwc->currentIndex()==1)//非同步测量
        {
            for(int i=0;i<12;i++)
            {
                if (watched ==newAllPage->widget[i])
                {
                    if (e->type() == QEvent::Paint)
                    {
//                        for(int j=0;j<12;j++)
//                        {
//                            if (j!=i)
//                                m_clnp->recvThread->SetChannelShow(j,false);
//                        }
                        allChannelShow = i;

                        f_paintOnLubo(newAllPage->widget[i]);

                        for(int j=0;j<12;j++) m_clnp->recvThread->SetChannelShow(j,true);

                        if( (i == 11) && m_bIsConn)
                        {
                            QString str="1g";

                            for( int i=0; i < 12; i++)
                            {
                                str += ":" + QString::number(maxInChanel[i]/10000,'f',2);
                            }

                            tcpServer->TcpSend(str);
                        }

                        return true;
                    }
                    else if (e->type() == QEvent::MouseButtonRelease)//双击的话用QEvent::MouseButtonDblClick
                    {
                        pagesWidget->setCurrentIndex(0);
                        setTestText(0);
                 //       labInfo->setText(tr(""));
               //         ui->frakey->setVisible(false);
                        showAllTimer->stop();
                     //   timer->stop();
                        int iTdh=getTdh()-1;
                        iTdh+=i;
                        /*
                        int iChannel=iTdh+1;
                        int imChannel = iChannel % 12;
                        int icChannel = iChannel / 12;
                        QModelIndex index;
                        for(int i=1;i<13;i++)
                        {
                            index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
                            if (imChannel==0)
                                newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
                            else
                                newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
                        }
                        */
                        newTestPage->f_wcPage->cboBctd->setCurrentIndex(iTdh);
                        NetTest();
                    }
                }
            }
        }
        else
        {
            for(int i=0;i<12;i++)
            {
                if (watched == newAllPage->widget[i])
                {
                    if (e->type() == QEvent::Paint)
                    {
//                        for(int j=0;j<12;j++)
//                        {
//                            if (j!=i)
//                                cappacket->SetChannelShow(j,false);
//                        }
                        allChannelShow = i;

                        paintOnLubo(newAllPage->widget[i]);

                        for(int j=0;j<12;j++) cappacket->SetChannelShow(j,true);

                        if( (i == 11) && m_bIsConn)
                        {
                            QString str="1g";

                            for( int i=0; i < 12; i++)
                            {
                                str += ":" + QString::number(maxInChanel[i]/10000,'f',2);
                            }

                            tcpServer->TcpSend(str);
                        }

                        return true;
                    }
                    else if (e->type() == QEvent::MouseButtonRelease)//双击的话用QEvent::MouseButtonDblClick
                    {
                        pagesWidget->setCurrentIndex(0);
                        setTestText(0);
                 //       labInfo->setText(tr(""));
               //         ui->frakey->setVisible(false);
                        showAllTimer->stop();
                     //   timer->stop();
                        int iTdh=getTdh()-1;
                        iTdh+=i;
                        /*
                        int iChannel=iTdh+1;
                        int imChannel = iChannel % 12;
                        int icChannel = iChannel / 12;
                        QModelIndex index;
                        for(int i=1;i<13;i++)
                        {
                            index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
                            if (imChannel==0)
                                newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
                            else
                                newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
                        }
                        */
                        newTestPage->cboBctd->setCurrentIndex(iTdh);
                        NetTest();
                    }
                }
            }
        }

        return true;
    }
//    if (watched==newAddPage->tabControl)         //首先判断控件
//    {
//        if (e->type()==9)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//         {
//          //   QPalette p=QPalette();
//          //   p.setColor(QPalette::Base,Qt::green);
//          //   newParaPage->txtBzXdy->setPalette(p);
//            // ui->frakey->setGeometry(120,50,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=30;
//            QModelIndex index = newAddPage->tabControl->currentIndex();
//            if (index.column()!=9)
//            {
//                keywidget->toShow();
//                keywidget->move(100,80); // to move keyboard
//                focusIn=13;
//            }
//            else
//            {
//                newAddPage->tabControl->clearFocus();
//                keywidget->toHide();
//            }
//         }
//    }
//    if (watched==newAddPage->tabChannel)         //首先判断控件
//    {
//        if (e->type()==9)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//         {
//         //    QPalette p=QPalette();
//          //   p.setColor(QPalette::Base,Qt::green);
//          //   newParaPage->txtBzXdy->setPalette(p);
//          //   ui->frakey->setGeometry(120,50,161,211);
//           //  ui->frakey->setVisible(true);
//             keywidget->toShow();
//             keywidget->move(100,80); // to move keyboard
//             focusIn=14;
//         }
//    }
//    if (watched==newAddPage->tabMn)         //首先判断控件
//    {
//        if (e->type()==9)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//         {
//         //    QPalette p=QPalette();
//          //   p.setColor(QPalette::Base,Qt::green);
//          //   newParaPage->txtBzXdy->setPalette(p);
//          //   ui->frakey->setGeometry(120,50,161,211);
//           //  ui->frakey->setVisible(true);
//             keywidget->toShow();
//             keywidget->move(100,80); // to move keyboard
//             focusIn=15;
//         }
//    }
//    if (watched == newAddPage->txtPercent)
//    {
//        if (e->type()==8)
//        {
//            keywidget->toShow();
//            keywidget->move(100,80); // to move keyboard

//            newAddPage->txtPercent->setStyleSheet("color:yellow");
//            focusIn=29;
//        }
//        else if(e->type()==9)
//        {
//            keywidget->toHide();
//            newAddPage->txtPercent->setStyleSheet("color:white");
//        }
//    }
//    if (watched == newAddPage->txtUn)
//    {
//        if (e->type()==8)
//        {
//            keywidget->toShow();
//            keywidget->move(100,80); // to move keyboard

//            newAddPage->txtUn->setStyleSheet("color:yellow");
//            focusIn=28;
//        }
//        else if(e->type()==9)
//        {
//            keywidget->toHide();
//            newAddPage->txtUn->setStyleSheet("color:white");
//        }
//    }
//    if (watched==newAddPage->tabHarmonic)         //首先判断控件
//    {
//        if (e->type()==9)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//        {
//            QModelIndex index = newAddPage->tabHarmonic->currentIndex();

//            if(index.column()!=0)
//            {
//                keywidget->toShow();
//                keywidget->move(100,80); // to move keyboard
//                focusIn=16;
//            }
//            else
//            {
//                newAddPage->tabControl->clearFocus();
//                keywidget->toHide();
//            }
//        }
//    }
//    if (watched==newTestPage->txtBzXdy)         //首先判断控件(这里指 txtBzXdy)
//    {
//         if (e->type()==QEvent::FocusIn)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//         {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->txtBzXdy->setPalette(p);
//          //   ui->frakey->setGeometry(435,50,161,211);
//          //   ui->frakey->setVisible(true);
//             keywidget->toShow();
//             keywidget->move(300,100); // to move keyboard
//             focusIn=0;
//         //    bzorbc=0;
//         }
//         else if (e->type()==QEvent::FocusOut)    // 这里指 txtBzXdy 控件的失去焦点事件
//         {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->txtBzXdy->setPalette(p);
//        //     ui->frakey->setVisible(false);
//             keywidget->toHide();
//          }
//    }
//    if (watched==newTestPage->txtBcXdy)           //这里来处理 txtBcXdy , txtBzXdy 是一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->txtBcXdy->setPalette(p);
//           //  ui->frakey->setGeometry(435,50,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=1;
//             keywidget->toShow();
//             keywidget->move(300,130); // to move keyboard
//             focusIn=1;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->txtBcXdy->setPalette(p);
//          //   ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newTestPage->txtEdyc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->txtEdyc->setPalette(p);
//           //  ui->frakey->setGeometry(435,50,161,211);
//          //   ui->frakey->setVisible(true);
//          //   bzorbc=2;
//             keywidget->toShow();
//             keywidget->move(230,190); // to move keyboard
//             focusIn=2;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->txtEdyc->setPalette(p);
//          //   ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newTestPage->f_wcPage->txtBzXdy)         ////LM 非同步测量
//    {
//         if (e->type()==QEvent::FocusIn)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//         {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->f_wcPage->txtBzXdy->setPalette(p);
//          //   ui->frakey->setGeometry(435,50,161,211);
//          //   ui->frakey->setVisible(true);
//             keywidget->toShow();
//             keywidget->move(300,100); // to move keyboard
//             focusIn=30;
//         //    bzorbc=0;
//         }
//         else if (e->type()==QEvent::FocusOut)    // 这里指 txtBzXdy 控件的失去焦点事件
//         {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->f_wcPage->txtBzXdy->setPalette(p);
//        //     ui->frakey->setVisible(false);
//             keywidget->toHide();
//          }
//    }
//    if (watched==newTestPage->f_wcPage->txtBcXdy)           //LM 非同步测量
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->f_wcPage->txtBcXdy->setPalette(p);
//           //  ui->frakey->setGeometry(435,50,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=1;
//             keywidget->toShow();
//             keywidget->move(300,130); // to move keyboard
//             focusIn=31;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->f_wcPage->txtBcXdy->setPalette(p);
//          //   ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newTestPage->f_wcPage->txtEdyc)           //LM非同步测量
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->f_wcPage->txtEdyc->setPalette(p);
//           //  ui->frakey->setGeometry(435,50,161,211);
//          //   ui->frakey->setVisible(true);
//          //   bzorbc=2;
//             keywidget->toShow();
//             keywidget->move(230,190); // to move keyboard
//             focusIn=32;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->f_wcPage->txtEdyc->setPalette(p);
//          //   ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if(watched == newTestPage->f_wcPage->txtMUYS)
//    {
//        if (e->type()==QEvent::FocusIn)
//       {
//            QPalette p=QPalette();
//            p.setColor(QPalette::Base,Qt::green);
//            newTestPage->f_wcPage->txtMUYS->setPalette(p);
//          //  ui->frakey->setGeometry(435,50,161,211);
//         //   ui->frakey->setVisible(true);
//         //   bzorbc=2;
//            keywidget->toShow();
//            keywidget->move(100,80); // to move keyboard
//            focusIn=34;
//        }
//       else if (e->type()==QEvent::FocusOut)
//       {
//            QPalette p=QPalette();
//            p.setColor(QPalette::Base,Qt::white);
//            newTestPage->f_wcPage->txtMUYS->setPalette(p);
//         //   ui->frakey->setVisible(false);
//            keywidget->toHide();
//       }
//    }
//    /*
//    if (watched==newTestPage->txtXbYxz)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->txtXbYxz->setPalette(p);
//          //   ui->frakey->setGeometry(435,50,161,211);
//          //   ui->frakey->setVisible(true);
//          //   bzorbc=7;
//             keywidget->toShow();
//             keywidget->move(270,170); // to move keyboard
//             focusIn=3;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->txtXbYxz->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    */
//    if (watched==newSysPage->txtMima)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//           //  newSysPage->txtMima->setPalette(p);
//           //  ui->frakey->setGeometry(460,50,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=3;
//             keywidget->toShow();
//             keywidget->move(245,380); // to move keyboard
//             focusIn=4;

//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtMima->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    /*
//    if (watched==newSysPage->txtBcbc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtBcbc->setPalette(p);
//           //  ui->frakey->setGeometry(410,50,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=4;
//             keywidget->toShow();
//             keywidget->move(225,110); // to move keyboard
//             focusIn=5;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtBcbc->setPalette(p);
//             ui->frakey->setVisible(false);
//        }
//    }

//    if (watched==newSysPage->txtJcbc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtJcbc->setPalette(p);
//             ui->frakey->setGeometry(410,50,161,211);
//             ui->frakey->setVisible(true);
//             bzorbc=5;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtJcbc->setPalette(p);
//             ui->frakey->setVisible(false);
//        }
//    }
//    */
//    if (watched==newLuboPage->txtLuboTime)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newLuboPage->txtLuboTime->setPalette(p);
//           //  ui->frakey->setGeometry(410,150,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=8;
//             keywidget->toShow();
//             keywidget->move(340,190); // to move keyboard
//             focusIn=5;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newLuboPage->txtLuboTime->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    /*
//    if (watched==newSysPage->txtBCCYSL)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtBCCYSL->setPalette(p);
//             ui->frakey->setGeometry(410,10,161,211);
//             ui->frakey->setVisible(true);
//             bzorbc=9;

//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtBCCYSL->setPalette(p);
//             ui->frakey->setVisible(false);
//        }
//    }
//    */
//    if (watched==newSysPage->txtSysXs)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtSysXs->setPalette(p);
//          //   ui->frakey->setGeometry(410,10,161,211);
//          //   ui->frakey->setVisible(true);
//         //    bzorbc=10;
//             keywidget->toShow();
//             keywidget->move(410,380); // to move keyboard
//             focusIn=6;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtSysXs->setPalette(p);
//          //   ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtSysBc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtSysBc->setPalette(p);
//           //  ui->frakey->setGeometry(410,10,161,211);
//           //  ui->frakey->setVisible(true);
//          //   bzorbc=11;
//             keywidget->toShow();
//             keywidget->move(410,380); // to move keyboard
//             focusIn=7;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtSysBc->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtSysJc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtSysJc->setPalette(p);
//          //   ui->frakey->setGeometry(410,10,161,211);
//           //  ui->frakey->setVisible(true);
//          //   bzorbc=12;
//             keywidget->toShow();
//             keywidget->move(410,380); // to move keyboard
//             focusIn=8;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtSysJc->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==txtXh)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             txtXh->setPalette(p);
//           //  ui->frakey->setGeometry(460,10,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=20;
//             keywidget->toShow();
//             keywidget->move(420,140); // to move keyboard
//             focusIn=9;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             txtXh->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==txtSj)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             txtSj->setPalette(p);
//           //  ui->frakey->setGeometry(460,10,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=21;
//             keywidget->toShow();
//             keywidget->move(420,140); // to move keyboard
//             focusIn=10;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             txtSj->setPalette(p);
//          //   ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newTestPage->txtTestNum)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->txtTestNum->setPalette(p);
//           //  ui->frakey->setGeometry(460,10,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=22;
//             keywidget->toShow();
//             keywidget->move(330,200); // to move keyboard
//             focusIn=11;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->txtTestNum->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newTestPage->f_wcPage->txtTestNum)           //LM 非同步测量
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->f_wcPage->txtTestNum->setPalette(p);
//           //  ui->frakey->setGeometry(460,10,161,211);
//           //  ui->frakey->setVisible(true);
//           //  bzorbc=22;
//             keywidget->toShow();
//             keywidget->move(330,200); // to move keyboard
//             focusIn=33;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->f_wcPage->txtTestNum->setPalette(p);
//           //  ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }//LM 非同步测量
//    if (watched==newSysPage->txtbc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtbc->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=20;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtbc->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtbc1)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtbc1->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=21;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtbc1->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtbc2)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtbc2->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=22;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtbc2->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtbc3)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtbc3->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=23;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtbc3->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtjc)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtjc->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=24;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtjc->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtjc1)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtjc1->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=25;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtjc1->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtjc2)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtjc2->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=26;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtjc2->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    if (watched==newSysPage->txtjc3)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newSysPage->txtjc3->setPalette(p);
//             keywidget->toShow();
//             keywidget->move(390,190); // to move keyboard
//             focusIn=27;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newSysPage->txtjc3->setPalette(p);
//             keywidget->toHide();
//        }
//    }
//    /*
//    if (watched==newTestPage->txtYanshi)           //这里来处理 一样的
//    {
//         if (e->type()==QEvent::FocusIn)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::green);
//             newTestPage->txtYanshi->setPalette(p);
//           //  ui->frakey->setGeometry(480,10,161,211);
//          //   ui->frakey->setVisible(true);
//          //   bzorbc=23;
//             keywidget->toShow();
//             keywidget->move(400,200); // to move keyboard
//             focusIn=12;
//         }
//        else if (e->type()==QEvent::FocusOut)
//        {
//             QPalette p=QPalette();
//             p.setColor(QPalette::Base,Qt::white);
//             newTestPage->txtYanshi->setPalette(p);
//         //    ui->frakey->setVisible(false);
//             keywidget->toHide();
//        }
//    }
//*/
    return QWidget::eventFilter(watched, e); // 最后将事件交给上层对话框
}

void feedBeeper(QString path)
{
    QFile file( path );
    if ( file.exists())
    {
        return;
    }

    if(! file.open( QIODevice::WriteOnly ) )
    {
        myHelper::ShowMessageBoxError("i can't make new file!");
    }

    file.close();
}

void MainWindow::StartLuBo()
{
#ifndef i386
    feedBeeper("/opt/python/beeper");
#else
    feedBeeper("beeper");
#endif
    int iTime=0;

    iTime = newLuboPage->combLuboTime->currentIndex()+1;
//    iTime = 1;

    newLuboPage->combLuboTime->setCurrentIndex(0);
    newLuboPage->btnLuboData->setEnabled(false);
    newLuboPage->txtLuboTime->setText(QString::number(iTime));
    newLuboPage->txtLubo->setText("");
    newLuboPage->scrllCurve->setValue(0);
    newLuboPage->scrllCurve->setMinimum(0);
    newLuboPage->scrllCurve->setMaximum(0);
    newLuboPage->tSlider->setValue(0);

    luboIsEnd = false;

    iTestMode=2;    //录波

    if (!cappacket->IsOpen())
    {
        cappacket->StopCap(false);
        openNetFlag=cappacket->Open(newTestPage->cboCyfs->currentIndex());
        openNetTimer->start(1000);

        if(!openNetFlag)
        {
            // QMessageBox::information(NULL,"初始化结果","初始化失败！");
            myHelper::ShowMessageBoxError(tr("初始化失败！"));
            return;
        }
        else
        {
            openNetTimer->stop();
            openNetFlag=false;
        }
    }

    qDebug()<<"open successfully!";

    dblFuZhi_HGQ=11585;
    cappacket->init();
    guiyue=cappacket->GuiYueType();
    m_iPeriodCnt=iTime*50;
    m_dblShowPeriods = m_iPeriodCnt;

    ChangeX_Text(); // this function will make two paint

    cappacket->SetCapParamater(TestChannel_LuBo,m_iPeriodCnt,0,11585);
    for(int i=0;i<12;i++)
       cappacket->SetChannelShow(i,true);
    //  myNetProc->ProcessStart(TestChannel_LuBo, m_iPeriodCnt, 11585, iStartPoint);
  //  cappacket->setIsOK(true);
    m_MaxSZL=0;
    //update();

    cappacket->setIsOK(false);
    cappacket->setTestType(iTestMode);          // cappacket->setTestType(2);          //录波

    cappacket->setMacGl(1);
    cappacket->pcap_lubo();
    cappacket->start();
  //  cappacket->pcap_lubo();
    //timer->start( 500 );
    cappacket->StopCap(false);

    qDebug()<<"Lubo settings is done!";

    labInfo->setText("录波开始，请稍等！");
    widgetInfo->show();
    showInfoTimer->start(500);
}
void MainWindow::tTest()
{
    m_dblShowPeriods = m_iPeriodCnt + (double)newLuboPage->tSlider->value() / (double)newLuboPage->tSlider->maximum()
                                                                            * (1 - m_iPeriodCnt);
    double dblWeiZi;
    if(newLuboPage->scrllCurve->maximum() != 0)
            dblWeiZi = (double)newLuboPage->scrllCurve->value() / (double)newLuboPage->scrllCurve->maximum();		// 滚动条位置
    else
            dblWeiZi = 0;
    if (m_iPeriodCnt == m_dblShowPeriods)
    {
            newLuboPage->scrllCurve->setMaximum(0);
    }else
    {
            newLuboPage->scrllCurve->setMaximum((m_iPeriodCnt - m_dblShowPeriods) * 4);
            if(newLuboPage->scrllCurve->maximum() < 1)
                newLuboPage->scrllCurve->setMaximum(1);
    }
    newLuboPage->scrllCurve->setValue( dblWeiZi * newLuboPage->scrllCurve->maximum());
    scrllCurveScroll();
}
void MainWindow::selectTd(bool flag)
{
    if (flag)
    {
        newLuboPage->labColor1->setStyleSheet("background-color:#008000");
        newLuboPage->labColor2->setStyleSheet("background-color:#808000");
        newLuboPage->labColor3->setStyleSheet("background-color:#000080");
        newLuboPage->labColor4->setStyleSheet("background-color:#800080");
        newLuboPage->labColor5->setStyleSheet("background-color:#008080");
        newLuboPage->labColor6->setStyleSheet("background-color:#808080");
        newLuboPage->labColor7->setStyleSheet("background-color:#C0C0C0");
        newLuboPage->labColor8->setStyleSheet("background-color:#FF0000");
        newLuboPage->labColor9->setStyleSheet("background-color:#00FF00");
        newLuboPage->labColor10->setStyleSheet("background-color:#FFFF00");
        newLuboPage->labColor11->setStyleSheet("background-color:#0000FF");
        newLuboPage->labColor12->setStyleSheet("background-color:#FF00FF");
    }
    else
    {
        newLuboPage->labColor1->setStyleSheet("background-color:#191919");
        newLuboPage->labColor2->setStyleSheet("background-color:#191919");
        newLuboPage->labColor3->setStyleSheet("background-color:#191919");
        newLuboPage->labColor4->setStyleSheet("background-color:#191919");
        newLuboPage->labColor5->setStyleSheet("background-color:#191919");
        newLuboPage->labColor6->setStyleSheet("background-color:#191919");
        newLuboPage->labColor7->setStyleSheet("background-color:#191919");
        newLuboPage->labColor8->setStyleSheet("background-color:#191919");
        newLuboPage->labColor9->setStyleSheet("background-color:#191919");
        newLuboPage->labColor10->setStyleSheet("background-color:#191919");
        newLuboPage->labColor11->setStyleSheet("background-color:#191919");
        newLuboPage->labColor12->setStyleSheet("background-color:#191919");
    }
    newLuboPage->chkSelectAll->setChecked(flag);
    for(int i=0;i<12;i++)
    {
        if (flag)
        {
            if (ys[i] % 2 != 0)
             ys[i]++;
        }
        else
        {
            if (ys[i] % 2 == 0)
             ys[i]++;
        }
    }
    showLubo();
}
void MainWindow::showLubo()
{
  //  if (iTestMode==0)   //如果是测量则退出
  //      return;
    for(int i=0;i<12;i++)
    {
       if (ys[i] % 2 == 0)
       {
         cappacket->SetChannelShow(i,true);
       }
       else
       {
         cappacket->SetChannelShow(i,false);
       }
    }
    luboSelect();
}
void MainWindow::changeys(ClickedLabel* labys)
{
    int index=labys->text().toInt()-1;
    ys[index]++;
    switch(index)
    {
    case 0:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#008000");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 1:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#808000");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 2:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#000080");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 3:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#800080");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 4:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#008080");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 5:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#808080");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 6:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#C0C0C0");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 7:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#FF0000");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 8:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#00FF00");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 9:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#FFFF00");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 10:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#0000FF");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    case 11:
        if (ys[index] % 2 == 0)
            labys->setStyleSheet("background-color:#FF00FF");
        else
            labys->setStyleSheet("background-color:#191919");
        break;
    }
    int iAllSelectNo=0;
    for(int i=0;i<12;i++)
    {
        if (ys[i] % 2 != 0)
            iAllSelectNo++;
    }
    if (iAllSelectNo==0)
    {
        newLuboPage->chkSelectAll->setCheckState(Qt::Checked);
    }
    else if(iAllSelectNo<12)
    {
        newLuboPage->chkSelectAll->setCheckState(Qt::PartiallyChecked);
    }
    else
    {
        newLuboPage->chkSelectAll->setCheckState(Qt::Unchecked);
    }

    showLubo();
  //  qDebug()<<ys->text();
}
void MainWindow::luboSelect()
{
 //   cappacket->setIsOK(true);
 //   timer->start(100);
    qDebug()<<"paint on zoom in/out";
    update();
}
void MainWindow::scrllCurveScroll()
{
    if (newLuboPage->scrllCurve->maximum()!= 0)
    {
            double dblK = (m_iPeriodCnt - m_dblShowPeriods)/ (double)newLuboPage->scrllCurve->maximum();
            m_iStartPoint = (double)newLuboPage->scrllCurve->value() * dblK * cappacket->SmpRate();
    }
    else
    {
            m_iStartPoint = 0;
    }

    ChangeX_Text();
    luboSelect();
   // pboxCurve->Invalidate();
   // qDebug()<<newLuboPage->scrllCurve->value();
}
void MainWindow::ChangeX_Text()
{
        double dblBuChang;		// 横坐标步长
        dblBuChang = ((double)(cappacket->SmpRate() * m_dblShowPeriods)) / (X_Cnt - 1);

        for(int iTemp = 0; iTemp <= X_Cnt-1; iTemp++)
        {
            double dtemp=(m_iStartPoint + dblBuChang * iTemp ) / 50 / cappacket->SmpRate();
            newLuboPage->lblYY[iTemp]->setText(QString::number(dtemp,'f',2));
        }
       //         gboxDraw->Controls["lblYY_" + iTemp]->Text = (double(m_iStartPoint + dblBuChang * (iTemp - 1)) / 50 / cappacket->SmpRate()).ToString("0.00");
}
void MainWindow::slotLuboData()
{
    QDir toDir = QDir::currentPath();
    QString fa =toDir.currentPath() +"/pcap";
    QString fileName="";
    fileName= QFileDialog::getOpenFileName(this, tr("open file"), fa, tr("pcap file(*.pcap)"));
    if (fileName=="")
    {
        qDebug()<<"打开录波文件失败!";
        return;
    }
    newLuboPage->scrllCurve->setValue(0);
    newLuboPage->scrllCurve->setMinimum(0);
    newLuboPage->scrllCurve->setMaximum(0);
    newLuboPage->tSlider->setValue(0);
    for(int i=0;i<12;i++)
       cappacket->SetChannelShow(i,true);
    cappacket->pcap_openFile(fileName);
    dblFuZhi_HGQ=11585;
    m_dblShowPeriods=(newLuboPage->combLuboTime->currentIndex() + 1)*50;
    m_iPeriodCnt=(newLuboPage->combLuboTime->currentIndex() + 1)*50;
    ChangeX_Text();
    newLuboPage->txtLuboTime->setText(QString::number(cappacket->ZhouQi()));
    iTestMode=2;
}

void MainWindow::tdSelect()
{
 /*   if (newTestPage->rdoCltd->isChecked())
    {
        */
        int iChannel=newTestPage->cboBctd->currentText().toInt();
        iChannel %=12;
        if (iChannel==0)
            iChannel=12;
        for(int i=0;i<12;i++)
        {
            if (i==iChannel-1)
                cappacket->SetChannelShow(i,true);
            else
                cappacket->SetChannelShow(i,false);
        }
        /*
    }
    else if(newTestPage->rdoAlltd->isChecked())
    {
        for(int i=0;i<12;i++)
           cappacket->SetChannelShow(i,true);
    }
    */
}


void MainWindow::initTest()
{
    testnum=0;
    yanshiNum=0;
    bzMax=0;
    bcMax=0;
    syncFlag=-1;
    m_bData=false;
    bmstart=false;
    bStart=false;
    iStart=0;
    pWc=0;
    temppWc=0;
        m_iTestTimes = 0;
        m_iTestTimes_YouXiao = 0;
        m_iTestTimes_Bc=0;
        m_iTestTimes_Jc=0;
        m_iTestTimes_BzYxz=0;
        m_iTestTimes_BcYxz=0;
        m_iTestTimes_BzXw=0;
        m_iTestTimes_BcXw=0;
        m_dblJC_Cnt = 0;
        m_dblBC_Cnt = 0;
        m_dblAvg_BC = 0;
        m_dblAvg_JC = 0;
        //m_dblPre_BC = 0;
      //  m_dblPre_BC = 0;
        memset(m_dblAll_BC,0,sizeof(m_dblAll_BC));
        memset(m_dblAll_JC,0,sizeof(m_dblAll_JC));
        memset(m_dblAll_avgBC,0,sizeof(m_dblAll_avgBC));
        memset(m_dblAll_avgJC,0,sizeof(m_dblAll_avgJC));
        memset(m_dblAll_BcYxz,0,sizeof(m_dblAll_BcYxz));
        memset(m_dblAll_BzYxz,0,sizeof(m_dblAll_BzYxz));
        memset(m_dblAll_BcXw,0,sizeof(m_dblAll_BcXw));
        memset(m_dblAll_BzXw,0,sizeof(m_dblAll_BzXw));
        m_dblMaxJC=0;
        m_dblMinJC=0;
        m_dblMaxBC=0;
        m_dblMinBC=0;
        m_iBiJiaoCiShu = m_iAvgNum;
        memset(m_BC,0,sizeof(m_BC));
        memset(m_JC,0,sizeof(m_JC));
        m_iTestNum=0;

}
bool MainWindow::calculateAvg()
{
    if (!bmstart)
    {
        bmstart=true;
        double temp=std::abs(newTestPage->txtJc->text().toDouble() - pWc);
        pWc=newTestPage->txtJc->text().toDouble();
        if (temp<=5.0)
        {
            iStart++;
            if (iStart>=2)
            {
                bmstart=true;
                iStart=0;
            }
        }
        else
        {
        return false;
        }
   }
   if (m_iBiJiaoCiShu==0)
   {
       m_iTestTimes=0;
       return false;
   }
   /*
   if (m_iTestTimes==1)
   {
       m_dblMaxJC=m_dblJC;
       m_dblMinJC=m_dblJC;
       m_dblMaxBC=m_dblBC;
       m_dblMinBC=m_dblBC;
   }
*/
   m_dblAll_avgBC[m_iTestTimes_YouXiao]=newTestPage->txtBc->text().toDouble();
   m_dblAll_avgJC[m_iTestTimes_YouXiao]=newTestPage->txtJc->text().toDouble();

   m_iTestTimes_YouXiao++;		// 有效测量次数加1
   if(m_iTestTimes_YouXiao >= m_iBiJiaoCiShu)
   {
     //   double tempBc=SZLB(m_iTestTimes_YouXiao,m_dblAll_avgBC);
     //   double tempJc=SZLB(m_iTestTimes_YouXiao,m_dblAll_avgJC);
        for(int i=0;i<m_iBiJiaoCiShu-1;i++)
        {
            m_dblAll_avgBC[i]=m_dblAll_avgBC[i+1];
            m_dblAll_avgJC[i]=m_dblAll_avgJC[i+1];
        }
     //   m_iTestTimes_YouXiao--;
        m_iTestTimes_YouXiao=0;
        m_dblBC_Cnt=0;
        m_dblJC_Cnt=0;
    }
    return true;
}

void MainWindow::showBcdata()
{
    QString bzbc="00";
    if (newSysPage->cboBzbc->currentIndex()==0)
        bzbc="00";
    else if (newSysPage->cboBzbc->currentIndex()==1)
        bzbc="11";
    else if (newSysPage->cboBzbc->currentIndex()==2)
        bzbc="04";
    else if (newSysPage->cboBzbc->currentIndex()==3)
        bzbc="14";
    else if (newSysPage->cboBzbc->currentIndex()==4)
        bzbc="24";
    else if (newSysPage->cboBzbc->currentIndex()==5)
        bzbc="44";
    else if (newSysPage->cboBzbc->currentIndex()==6)
        bzbc="05";
    else if (newSysPage->cboBzbc->currentIndex()==7)
        bzbc="15";
    else if (newSysPage->cboBzbc->currentIndex()==8)
        bzbc="25";
    else if (newSysPage->cboBzbc->currentIndex()==9)
        bzbc="45";
    else if (newSysPage->cboBzbc->currentIndex()==10)
        bzbc="22";
    else if (newSysPage->cboBzbc->currentIndex()==11)
        bzbc="33";
    systemLoad(bzbc);
}

double MainWindow::SZLB(int num,double*D_ADD)//num组double类型的数，去掉一个最大一个最小，再取平均
{
        int i;
        double Max_Data;
        double Min_Data;
        double Result;

        Max_Data=Min_Data=Result=*D_ADD;

        for(i=1;i<num;i++)
        {
            Result+=(*(D_ADD+i));
            if(*(D_ADD+i)<Min_Data)
            {
                Min_Data=*(D_ADD+i);
            }
            if(*(D_ADD+i)>Max_Data)
            {
                Max_Data=*(D_ADD+i);
            }
        }
        if(num<=2)
            Result=(Result/num);	//如果num<=3,则num个数直接取平均
        else
            Result=(Result-Max_Data-Min_Data)/(num-2);//num>3,num个数去掉一个最大一个最小，再取平均
        return(Result);
}

double MainWindow::SZLBA(int num,double*D_ADD)//取平均数
{
        int i;
        double Result;

        Result=*D_ADD;
        for(i=1;i<num;i++)
        {
            Result+=(*(D_ADD+i));
        }

        Result=(Result/num);	//num个数直接取平均
        /*
        double cz= *(D_ADD+i-1) - Result;
        if (std::abs(cz)>0.01)
        {

            return(*(D_ADD+i-1));
        }
        else
            */
            return(Result);
}

void MainWindow::jsWc()
{   
    if(fake_pps_count < 5) // if no udp is received, do cal every 200*5 ms
    {
        fake_pps_count++;
    }
    else
    {
        fake_pps_count = 0;
    }

    if(fake_pps_count != 3) return; // 3*200 ms after udp is ready

    if(newTestPage->tabwc->currentIndex() == 1)
    {
        f_jsWc();
        return;
    }

    qDebug()<<"/n/n/n jswc!";
    static double bzYxz_old = 0;
    static double bzXw_old = 0;

    // if we wanna support more data sequence, we need a array_buffer
    if ((netYouXiaoZhi != 0)&&(netXiangWei != 0))
    {
        //qDebug()<<"sync num =" << tbsx;

        if (tbsx == 1)
        {
            ProcessData(netYouXiaoZhi*100,bzYxz,netXiangWei,bzXw);
        }
        else if(tbsx == 2)
        {
            if(bzYxz_old != 0 && bzXw_old != 0)
                ProcessData(cappacket->YouXiaoZhi()*100,bzYxz_old,cappacket->XiangWei(),bzXw_old);
        }
        else
        {
            ProcessData(cappacket->YouXiaoZhi()*100,bzYxz,cappacket->XiangWei(),bzXw);
        }

        showWcText();
    }

    bzYxz_old = bzYxz;
    bzXw_old = bzXw;

    bcYxz=m_dblYXZ_HGQ;
    netYouXiaoZhi=cappacket->YouXiaoZhi();
    netXiangWei=cappacket->XiangWei();
    //   update();
    udp->setIsOK(false);
}

void MainWindow::jsUdpWc()
{
    if(nowtest ==1)//LM非同步测量
    {
        bzMax=udp->getMaxPointValue();
        bzYxz=udp->YouXiaoZhi();
        bzYxz /=bzTestXs;
        bzYxz *= 100;
        bzXw=udp->XiangWei();
        int ifdxs=udp->getBzFdbs();
        if (ifdxs==1000)
            bzXw +=139;
        else if (ifdxs==100)
            bzXw +=14.5;
        else if (ifdxs==10)
            bzXw +=1.92;
        if (newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5)    //非9-1/2时
        {
            bcMax=udp->getMaxPointValue_Bc();
            bcYxz=udp->YouXiaoZhi_Bc();// * bcTestXs * 20 / 65535
            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==6)  //ft3时已经除好了不用再除
            {
                bcTestXs=udp->getFt3Xs();
            }
            bcYxz /=bcTestXs;
            bcYxz *= 100;
            bcXw=udp->XiangWei_Bc();
            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()!=6)  //ft3除外
            {
                int icfdxs=udp->getBcFdbs();
                if (icfdxs==1000)
                    bcXw +=139;
                else if (icfdxs==100)
                    bcXw +=14.5;
                else if (icfdxs==10)
                    bcXw +=1.92;
            }
            f_ProcessData(bcYxz,bzYxz,bcXw,bzXw);
            f_showWcText();

            qDebug()<<"paint on end of f_wccs";
            update();
            qDebug()<<"h";
            udp->setIsOK(false);
        }
    }
    else
    {
        bzMax=udp->getMaxPointValue();
        bzYxz=udp->YouXiaoZhi();
        bzYxz /=bzTestXs;
        bzYxz *= 100;
        bzXw=udp->XiangWei();
        int ifdxs=udp->getBzFdbs();
        if (ifdxs==1000)
            bzXw +=139;
        else if (ifdxs==100)
            bzXw +=14.5;
        else if (ifdxs==10)
            bzXw +=1.92;

        if (newTestPage->cboBcSelect->currentIndex()!=5)    //非9-1/2时
        {
            bcMax=udp->getMaxPointValue_Bc();
            bcYxz=udp->YouXiaoZhi_Bc();// * bcTestXs * 20 / 65535
            if (newTestPage->cboBcSelect->currentIndex()==6)  //ft3时已经除好了不用再除
            {
                bcTestXs=udp->getFt3Xs();

                //debug only
                //bcTestXs = 220000;
            }
            qDebug()<<"bcYxz"<<bcYxz;
            bcYxz /=bcTestXs;
            bcYxz *= 100;
            qDebug()<<"bcYxz"<<bcTestXs<<bcYxz;
            bcXw=udp->XiangWei_Bc();
            if (newTestPage->cboBcSelect->currentIndex()!=6)  //ft3除外
            {
                int icfdxs=udp->getBcFdbs();
                if (icfdxs==1000)
                    bcXw +=139;
                else if (icfdxs==100)
                    bcXw +=14.5;
                else if (icfdxs==10)
                    bcXw +=1.92;
            }
            ProcessData(bcYxz,bzYxz,bcXw,bzXw);
            showWcText();

            qDebug()<<"paint on end of wccs";
            update();
            udp->setIsOK(false);
        }
        else
        {
            fake_pps_count = 0;
        }
    }

    /*
    else if (newTestPage->cboBcSelect->currentIndex()==5)    //9-1/2时
    {
     //   jsWc();
      //  double bfd=bzyxz*100;
      //  newTestPage->txtBFB->setText(QString::number(bfd,'f',2));
    }
*/
}
void MainWindow::showWcText()
{
 //   labInfo->setText("d:"+QString::number(udp->getLost()));
 //   widgetInfo->show();
 //   showInfoTimer->start(2000);
    calculateAvg();

    if( fabs( m_dblBC ) < 10 )
    {
        m_dblYXZ_JYY = m_dblYXZ_HGQ / (1 + m_dblBC / 100);
    }

    newTestPage->txtBzYxz->setText(infnan(QString::number(m_dblYXZ_JYY,'f',5)));
    newTestPage->txtBzXw->setText(infnan(QString::number(m_dblXW_JYY,'f',2)));
    newTestPage->txtBcYxz->setText(infnan(QString::number(m_dblYXZ_HGQ,'f',5)));
    newTestPage->txtBcXw->setText(infnan(QString::number(m_dblXW_HGQ,'f',2)));
    newTestPage->txtBc->setText(infnan(QString::number(m_dblBC,'f',4)));
    newTestPage->txtJc->setText(infnan(QString::number(m_dblJC,'f',2)));
    newTestPage->txtBFB->setText(infnan(QString::number(m_dblYXZ_JYY,'f',2)));
    emit sigTestEnd();
    m_BC[m_iTestNum]=m_dblBC;
    m_JC[m_iTestNum]=m_dblJC;

    m_iTestNum++;
    if (m_iTestNum>2)
    {
        m_iTestNum=0;
        double avgbc=0;
        double avgjc=0;
        double maxbc=0;
        double maxjc=0;
        double minbc=0;
        double minjc=0;
            if (m_BC[0]>m_BC[1])
            {
                maxbc=m_BC[0];
                minbc=m_BC[1];
            }
            else
            {
                maxbc=m_BC[1];
                minbc=m_BC[0];
            }
            if (m_JC[0]>m_JC[1])
            {
                maxjc=m_JC[0];
                minjc=m_JC[1];
            }
            else
            {
                maxjc=m_JC[1];
                minjc=m_JC[0];
            }
        if (maxbc<m_BC[2])
        {
            maxbc=m_BC[2];
        }
        if (maxjc<m_JC[2])
        {
            maxjc=m_JC[2];
        }
        if (minbc>m_BC[2])
        {
            minbc=m_BC[2];
        }
        if (minjc>m_JC[2])
        {
            minjc=m_JC[2];
        }
        for(int i=0;i<3;i++)
        {
            avgbc +=m_BC[i];
            avgjc +=m_JC[i];
        }
        avgbc /=3;
        avgjc /=3;
        newTestPage->txtMaxBc->setText(infnan(QString::number(maxbc,'f',4)));
        newTestPage->txtMaxJc->setText(infnan(QString::number(maxjc,'f',2)));
        newTestPage->txtMinBc->setText(infnan(QString::number(minbc,'f',4)));
        newTestPage->txtMinJc->setText(infnan(QString::number(minjc,'f',2)));
        newTestPage->txtAvgBc->setText(infnan(QString::number(avgbc,'f',4)));
        newTestPage->txtAvgJc->setText(infnan(QString::number(avgjc,'f',2)));
    }

    qDebug()<<"Num of samples:"<<udp->getMaxPoint()<<udp->getMaxPoint_Bc();

    if (m_bIsConn)          //联机时上传误差数据;
    {
        QString s="1a:";
        s += QString::number(m_dblYXZ_JYY,'f',6);
        s += ":";
        s += QString::number(m_dblXW_JYY,'f',2);
        s += ":";
        s += QString::number(m_dblYXZ_HGQ,'f',6);
        s += ":";
        s += QString::number(m_dblXW_HGQ,'f',2);
        s += ":";
        s += QString::number(m_dblYXZ_JYY,'f',2);
        s += ":";
        s += QString::number(m_dblBC,'f',4);
        s += ":";
        s += QString::number(m_dblJC,'f',2);
        tcpServer->TcpSend(s);

        // send part of the samples, for wave painting
        QString strBuff="1b";

        int NumOfSamples = udp->getMaxPoint();

        for(int i = 0; i < NumOfSamples; i++)
        {
            strBuff += ":" + QString::number(udp->m_tempBz[i],'f',4);
        }

        tcpServer->TcpSend(strBuff);

        strBuff = "1c";
        NumOfSamples = udp->getMaxPoint_Bc();

        if(newTestPage->cboBcSelect->currentText() != "光纤 61850-9-2(LE)")
        {
            for(int i = 0; i < NumOfSamples; i++)
            {
                strBuff += ":" + QString::number(udp->m_tempBc[i],'f',4);
            }
        }
        else
        {
            for(int i = 0; i < 12; i++)
            {
                if(cappacket->GetChannelShow(i))
                {
                    for(int j = 0; j < 80; j++)
                    {
                        strBuff += ":" + QString::number(cappacket->m_tempArray[i][j],'f',1);
                    }
                    break;
                }
            }
        }

        tcpServer->TcpSend(strBuff);
    }
}

QString MainWindow::infnan(QString s)
{
    if (s.length() > 9) return s.left(9);

    if ((s=="inf")||(s=="nan"))
        return "/";
    else
        return s;
}

void MainWindow::paintOnLubo(QWidget *w)
{
  //  if (!cappacket->getIsOK())
  //      return;
  //  cappacket->StopCap(true);
    QPainter painter(w);
    QPoint beginPoint;
    QPoint endPoint;
    painter.translate(0,100);
    painter.drawLine(0,0,800,0);

    QPen greenPen;
    greenPen.setColor(Qt::green);
    greenPen.setWidth(3);

    float dblWidth, dblHeight;
    dblWidth = (float)w->width();
    dblHeight = (float)w->height();
    //   int iPoints;		// 点数
    float dblScaling_X, dblScaling_Y;		// X轴和Y轴的缩放比例
    double dblMaxBFB = 0.1;		// 最大百分表
    double m_iShuZiLiangMax=0;
    m_iShuZiLiangMax=m_MaxSZL;
    // m_iShuZiLiangMax=cappacket->getMaxShuZiLiang();
    if (m_iShuZiLiangMax==0.0)
        m_iShuZiLiangMax=0.1;
    qDebug()<<"m_iShuZiLiangMax"<<QString::number( m_iShuZiLiangMax, 'f', 2);
    double m_dblFuZhi=dblFuZhi_HGQ;
    double dblFZ=(double)m_iShuZiLiangMax / (double)m_dblFuZhi;
    if(dblMaxBFB < dblFZ)
        dblMaxBFB = dblFZ;
    dblMaxBFB += 0.05;

     if(m_iShuZiLiangMax != 0)
        //dblScaling_Y = dblHeight / ((float)m_dblFuZhi * dblMaxBFB * 2);
         dblScaling_Y = dblHeight / (m_iShuZiLiangMax * 2);
    else
        dblScaling_Y = 0;
//    if (iTestMode==2)
//        m_dblShowPeriods=cappacket->ZhouQi();
    for(int i = 0; i < 12; i++)
    {
        bool doShow = cappacket->GetChannelShow(i);

        if( iTestMode == 3)
        {
            if(i == allChannelShow)
            {
                doShow = true;
            }
            else
            {
                doShow = false;
            }
        }

        //qDebug()<<"channel "<<i<<doShow;

        if( doShow )
        {
            qDebug()<<"show channel"<<i;
            if (iTestMode == 3)
            {
                QPen greenPen;
                greenPen.setColor(Qt::green);
                greenPen.setWidth(3);

                painter.setPen(greenPen);
            }
            else
            {
                switch(i)
                {
                    case 0:
                            painter.setPen(QColor(0X00,0X80,0X00));
                            break;
                    case 1:
                            painter.setPen(QColor(0X80,0X80,0X00));
                            break;
                    case 2:
                            painter.setPen(QColor(0X00,0X00,0X80));
                            break;
                    case 3:
                            painter.setPen(QColor(0X80,0X00,0X80));
                            break;
                    case 4:
                            painter.setPen(QColor(0X00,0X80,0X80));
                            break;
                    case 5:
                            painter.setPen(QColor(0X80,0X80,0X80));
                            break;
                    case 6:
                            painter.setPen(QColor(0XC0,0XC0,0XC0));
                            break;
                    case 7:
                            painter.setPen(QColor(0XFF,0X00,0X00));
                            break;
                    case 8:
                            painter.setPen(QColor(0X00,0XFF,0X00));
                            break;
                    case 9:
                            painter.setPen(QColor(0XFF,0XFF,0X00));
                            break;
                    case 10:
                            painter.setPen(QColor(0X00,0X00,0XFF));
                            break;
                    case 11:
                            painter.setPen(QColor(0XFF,0X00,0XFF));
                            break;
                    default:
                            painter.setPen(Qt::red);
                            break;
                }
            }

            int iArrLen = m_dblShowPeriods * cappacket->SmpRate();
            dblScaling_X = dblWidth / ((float)iArrLen - 1);

            if(iTestMode == 2)
            {
                for(int j = 0; j < iArrLen-1; j++)
                {
                    beginPoint.setX(dblScaling_X * (float)j);
                    beginPoint.setY(dblHeight / 2 - cappacket->m_PointArray[i][m_iStartPoint+j]  * dblScaling_Y-100);
                    endPoint.setX(dblScaling_X * (float)(j+1) );
                    endPoint.setY(dblHeight / 2 - cappacket->m_PointArray[i][m_iStartPoint+j+1]  * dblScaling_Y-100);
                    painter.drawLine( beginPoint, endPoint );

                    //qDebug()<<"paintOnLubo"<<cappacket->m_PointArray[i][m_iStartPoint+j] ;
                }
            }
            else
            {
                for(int j = 0; j < iArrLen-1; j++)
                {
                    beginPoint.setX(dblScaling_X * (float)j);
                    beginPoint.setY(dblHeight / 2 - cappacket->m_tempArray[i][m_iStartPoint+j] * dblScaling_Y-100);
                    endPoint.setX(dblScaling_X * (float)(j+1) );
                    endPoint.setY(dblHeight / 2 - cappacket->m_tempArray[i][m_iStartPoint+j+1] * dblScaling_Y-100);
                    painter.drawLine( beginPoint, endPoint );

                    if( fabs(cappacket->m_tempArray[i][m_iStartPoint+j]) > maxInChanel[allChannelShow] )
                        maxInChanel[allChannelShow] = fabs(cappacket->m_tempArray[i][m_iStartPoint+j]);
                }
            }
        }
    }

    if (iTestMode == 2 && luboIsEnd)
    {
        newLuboPage->txtLubo->setText(cappacket->show_packet);
        newLuboPage->smvTree->setModel(cappacket->show_protocol);
        timer->stop();
        cappacket->StopCap(true);
        newLuboPage->btnLuboData->setEnabled(true);
        if(m_bIsConn)
            tcpServer->TcpSend("4a:" + cappacket->show_packet);
    }
}

void MainWindow::paintOnUdp(QWidget *w)
{
        QPainter painter(w);
        QPoint beginPoint;
        QPoint endPoint;
        painter.translate(0,100);
        painter.drawLine(0,0,800,0);
        float dblWidth, dblHeight;
        dblWidth = (float)w->width();
        dblHeight = (float)w->height();

        //int iPoints_Bz = udp->getMaxPoint()* udp->getZhouQi();
        int iPoints_Bz = udp->getMaxPoint();
        int iPoints_Bc=0;
        double dblMaxBFB = 0.1;		// 最大百分表
        double dblMaxYXZ;
        double bzMaxYXZ,bcMaxYXZ,bcMaxFz,bzMaxFz;
        bzMaxYXZ=bzYxz * 1.414 / 100;       //标准的最大有效值
     //   double m_dblFuZhi;         //仅对标准有效

        bzMaxFz=(double)bzMax / bzTestXs;
        float dblScaling_Xbz,dblScaling_Xbc;
        dblScaling_Xbz= dblWidth / ((float)iPoints_Bz - 1);
        if (newTestPage->cboBcSelect->currentIndex()!=5) //非9-1或者9-2
        {
            bcMaxYXZ=bcYxz * 1.414 / 100;
            bcMaxFz=(double)bcMax / bcTestXs;        //被测的最大有效值
       //     m_dblFuZhi=bzTestXs;
            //iPoints_Bc = udp->getMaxPoint_Bc() * udp->getZhouQi_bc();
            iPoints_Bc = udp->getMaxPoint_Bc();
        }
        else if(newTestPage->cboBcSelect->currentIndex()==5)  //9-1或者9-2
        {
            bcMaxYXZ=cappacket->YouXiaoZhi()*1.414;
            bcMax=cappacket->getMaxShuZiLiang();
            bcTestXs=dblFuZhi_HGQ;
            bcMaxFz=(double)bcMax / bcTestXs;        //被测的最大有效值
     //       m_dblFuZhi=dblFuZhi_HGQ;
            iPoints_Bc = 80;
        }
        if((iPoints_Bz==0)&&(iPoints_Bc==0))
            return;
    /*
        newTestPage->txtBzYxz->setText(QString::number(m_dblYXZ_JYY,'f',6));
        newTestPage->txtBzXw->setText(QString::number(m_dblXW_JYY,'f',2));
        newTestPage->txtBcYxz->setText(QString::number(m_dblYXZ_HGQ,'f',6));
        newTestPage->txtBcXw->setText(QString::number(m_dblXW_HGQ,'f',2));
        newTestPage->txtBc->setText(QString::number(m_dblBC,'f',4));
        newTestPage->txtJc->setText(QString::number(m_dblJC,'f',2));
        newTestPage->txtBFB->setText(QString::number(m_dblYXZ_JYY*100,'f',2));
    */
        dblScaling_Xbc= dblWidth / ((float)iPoints_Bc - 1);
        if(bzMaxYXZ>bcMaxYXZ)
            dblMaxYXZ=bzMaxYXZ;
        else
            dblMaxYXZ=bcMaxYXZ;
        if(dblMaxBFB < dblMaxYXZ)
            dblMaxBFB = dblMaxYXZ;
        double dblFZ=0;
        if(bzMaxFz>bcMaxFz)
            dblFZ=bzMaxFz;
        else
            dblFZ=bcMaxFz;
        if(dblMaxBFB < dblFZ)
            dblMaxBFB = dblFZ;

     //   qDebug()<<bzMaxYXZ<<","<<bzMaxFz<<"  "<<bcMaxYXZ<<","<<bcMaxFz;

        dblMaxBFB += 0.05;

        QString MaxBFB=QString::number(bzMaxFz*bzTestXs,'f',2);
        newTestPage->maxBfb->setText(MaxBFB);
        float dblScaling_Ybz = dblHeight / ((float)bzTestXs * dblMaxBFB * 2);
        float dblScaling_Ybc = dblHeight / ((float)bcTestXs * dblMaxBFB * 2);

    //标准图形
         //   int iZq=udp->getZhouQi();
         //   double dblBuChang = dblWidth / (iPoints_Bz);
            QPen newPen;
            newPen.setColor(Qt::red);
            newPen.setStyle(Qt::DashLine);
            painter.setPen(newPen);

            beginPoint.setX(0);
            beginPoint.setY(dblHeight / 2 -100);

            endPoint.setX(dblWidth);
            endPoint.setY(dblHeight / 2 -100);

            painter.drawLine( beginPoint, endPoint );

            painter.setPen(Qt::white);
            for(int i = 0; i < iPoints_Bz-1; i++)
            {
    /*
                beginPoint.setX(dblBuChang * (float)i);
                beginPoint.setY((dblHeight / 2) * (1 - udp->m_BzArray[i] / bzxs[newParaPage->cboBzSelect->currentIndex()]  / dblMaxBFB / bzTestXs)-100);
                endPoint.setX(dblBuChang * (float)i+1 );
                endPoint.setY((dblHeight / 2) * (1 - udp->m_BzArray[i+1] / bzxs[newParaPage->cboBzSelect->currentIndex()]  / dblMaxBFB / bzTestXs)-100);
                painter.drawLine(beginPoint, endPoint );
    */

                beginPoint.setX(dblScaling_Xbz * (float)i);
                beginPoint.setY(dblHeight / 2 - udp->m_tempBz[i] / bzxs[newTestPage->cboBzSelect->currentIndex()] * dblScaling_Ybz-100);
                endPoint.setX(dblScaling_Xbz * (float)(i+1) );
                endPoint.setY(dblHeight / 2 - udp->m_tempBz[i+1] / bzxs[newTestPage->cboBzSelect->currentIndex()] * dblScaling_Ybz-100);
                painter.drawLine( beginPoint, endPoint );
            //    qDebug()<<iPoints_Bz<<" "<<i<<" "<<udp->m_BzArray[i];

            }
     //       qDebug()<<"bz,"<<udp->m_BzArray[0]<<","<<udp->m_BzArray[1]<<","<<udp->m_BzArray[2];
    //被测图形

            if(newTestPage->cboBcSelect->currentIndex()!=5)  //非9-1或者9-2
            {
                painter.setPen(dataPen);
            //    double dblBuChang = dblWidth / (iPoints_Bc);
                for(int i = 0; i < iPoints_Bc-1; i++)
                {
    /*
                    beginPoint.setX(dblBuChang * (float)i);
                    beginPoint.setY((dblHeight / 2) * (1 - udp->m_BcArray[i] / bcxs[newParaPage->cboBcSelect->currentIndex()]  / dblMaxBFB /bcTestXs)-100);
                    endPoint.setX(dblBuChang * (float)i+1 );
                    endPoint.setY((dblHeight / 2) * (1 - udp->m_BcArray[i+1] / bcxs[newParaPage->cboBcSelect->currentIndex()]  / dblMaxBFB /bcTestXs)-100);
                    painter.drawLine(beginPoint, endPoint );

                    */
                    beginPoint.setX(dblScaling_Xbc * (float)i);
                    beginPoint.setY(dblHeight / 2 - udp->m_tempBc[i] / bcxs[newTestPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                    endPoint.setX(dblScaling_Xbc * (float)(i+1) );
                    endPoint.setY(dblHeight / 2 - udp->m_tempBc[i+1] / bcxs[newTestPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                    painter.drawLine( beginPoint, endPoint );
              //      qDebug()<<i<<" "<<udp->m_BcArray[i];
                }
                if(newTestPage->cboBcSelect->currentIndex()==6)  //ft3
                {
                    int tdh=newTestPage->cboBctd->currentText().toInt();
                    unsigned short bzw=0;
                    if (tdh<8)
                        bzw=(0x01<<(tdh+4)) & udp->etc_ft3.statusWord1;
                    else
                        bzw=(0x01<<(tdh-8)) & udp->etc_ft3.statusWord2;
                    if (bzw>0)
                    {
                        painter.setPen(Qt::red);
                        painter.drawText(715,-80,"数据无效");
                    }

                    unsigned short wxFlag=0x01 & udp->etc_ft3.statusWord1;      //维修标志
                    unsigned short jxFlag=(0x01<<1) & udp->etc_ft3.statusWord1; //检修标志test
                    unsigned short hxFlag=(0x01<<2) & udp->etc_ft3.statusWord1; //唤醒标志
               //     unsigned short tbffFlag=(0x01<<3) & udp->etc_ft3.statusWord1;//同步方法
                    unsigned short tbFlag=(0x01<<4) & udp->etc_ft3.statusWord1; //同步标志
                    QString sinfo="";
                    if (wxFlag>0)
                        sinfo +=tr("设备要求维修;");
                    if (jxFlag>0)
                        sinfo +=tr("检修标志位:试验;");
                    if (hxFlag>0)
                        sinfo +=tr("唤醒时间,全部数据无效;");
              //      labInfo->setText(sinfo);
                    QString btl=tr("波特率:");
                    btl +=QString::number((float)udp->etc_ft3.freq/10,'f',1);
                    if (tbFlag==0)
                    {
                        painter.setPen(Qt::green);
                        btl +=tr("M,已同步");
                    }
                    else
                    {
                        btl +=tr("M,未同步");
                        painter.setPen(Qt::yellow);
                    }
                    painter.drawText(1,-80,btl);
                }

            }
            else if(newTestPage->cboBcSelect->currentIndex()==5)  //9-1或者9-2
            {
            //    float dblScaling_X = dblWidth / ((float)iPoints - 1);
            //    float dblScaling_Y = dblHeight / ((float)m_dblFuZhi * dblMaxBFB * 2);
                for(int i = 0; i < 12; i++)
                {
                    if(cappacket->GetChannelShow(i))
                    {
                        painter.setPen(dataPen);
                        /*
                        switch(i)
                        {
                            case 0:
                                painter.setPen(QColor(0X00,0X80,0X00));
                                break;
                            case 1:
                                painter.setPen(QColor(0X80,0X80,0X00));
                                break;
                            case 2:
                                painter.setPen(QColor(0X00,0X00,0X80));
                                break;
                            case 3:
                                painter.setPen(QColor(0X80,0X00,0X80));
                                break;
                            case 4:
                                painter.setPen(QColor(0X00,0X80,0X80));
                                break;
                            case 5:
                                painter.setPen(QColor(0X80,0X80,0X80));
                                break;
                            case 6:
                                painter.setPen(QColor(0XC0,0XC0,0XC0));
                                break;
                            case 7:
                                painter.setPen(QColor(0XFF,0X00,0X00));
                                break;
                            case 8:
                                painter.setPen(QColor(0X00,0XFF,0X00));
                                break;
                            case 9:
                                painter.setPen(QColor(0XFF,0XFF,0X00));
                                break;
                            case 10:
                                painter.setPen(QColor(0X00,0X00,0XFF));
                                break;
                            case 11:
                                painter.setPen(QColor(0XFF,0X00,0XFF));
                                break;
                            default:
                                painter.setPen(Qt::red);
                                break;
                        }
                        */
                        for(int j = 0; j < iPoints_Bc-1; j++)
                        {
                            beginPoint.setX(dblScaling_Xbc * (float)j);     //tempbuff[i][j] m_PointArray

                            beginPoint.setY(dblHeight / 2 - cappacket->m_tempArray[i][j] / bcxs[newTestPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                          //  beginPoint.setY(dblHeight / 2 - tempbuff[i][j] / bcxs[newParaPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                            endPoint.setX(dblScaling_Xbc * (float)(j+1) );
                            endPoint.setY(dblHeight / 2 - cappacket->m_tempArray[i][j+1] / bcxs[newTestPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                         //   endPoint.setY(dblHeight / 2 - tempbuff[i][j+1] / bcxs[newParaPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                            painter.drawLine( beginPoint, endPoint );
                      //      qDebug()<<i<<" "<<j<<" "<<cappacket->m_PointArray[i][j];
                         }
                        break;
                    }
                }
                if(guiyue == GuiYue9_2)
                {
                    if (syncFlag==0)
                    {
                        painter.setPen(Qt::yellow);
                        painter.drawText(1,-80,"未同步");
                    }
                    else if (syncFlag==1)
                    {
                        painter.setPen(Qt::green);
                        painter.drawText(1,-80,"已同步");
                    }
                }
            }
    //}
            QString pl= "Freq=";
            double dblpl=udp->getPL();
            pl += QString::number(dblpl,'f',4);
            pl += "Hz";
            painter.setPen(Qt::cyan);
            painter.drawText(700,200,pl);

            int xwj=std::abs(newTestPage->txtJc->text().toDouble()/60);
            if ((dblpl>-35)&&(dblpl<65))
            {
                if ((newTestPage->txtBzYxz->text().toDouble()!=0.0)&&(newTestPage->txtBcYxz->text().toDouble()!=0))
                {
                    QString jx="";
                    if (xwj<60)
                        jx +=tr("极性:正");
                    else if ((xwj>120)&&(xwj<240))
                        jx +=tr("极性:反");
                    painter.setPen(Qt::darkCyan);
                    painter.drawText(1,200,jx);
                }
                else
                {
                    painter.drawText(1,200,"");
                }
            }

}

bool MainWindow::ProcessData(double dblYXZ_HGQ, double dblYXZ_JYY, double dblXW_HGQ, double dblXW_JYY)
{
    dblYXZ_HGQ /=bcxs[newTestPage->cboBcSelect->currentIndex()];
    dblYXZ_JYY /=bzxs[newTestPage->cboBzSelect->currentIndex()];
  //  qDebug()<<bzxs[newTestPage->cboBzSelect->currentIndex()];

    if (bmstart)        //已同步
    {
        if (m_iAvgNum>=2)
        {
            m_dblAll_BzYxz[m_iTestTimes_BzYxz]=dblYXZ_JYY;
            m_dblAll_BcYxz[m_iTestTimes_BcYxz]=dblYXZ_HGQ;
           //// m_dblAll_BzXw[m_iTestTimes_BzXw]=dblXW_JYY;
           //// m_dblAll_BcXw[m_iTestTimes_BcXw]=dblXW_HGQ;

            m_iTestTimes_BzYxz++;
            m_iTestTimes_BcYxz++;
            m_iTestTimes_BzXw++;
            m_iTestTimes_BcXw++;

            double sysxs=myDB->sysXs.toDouble();
           // double sysbc=myDB->sysBc.toDouble();
         //   double sysjc=myDB->sysJc.toDouble();

            double tempbzYxz=SZLBA(m_iTestTimes_BzYxz,m_dblAll_BzYxz);
            double cz= (m_dblAll_BzYxz[m_iTestTimes_BzYxz-1] - tempbzYxz)/m_dblAll_BzYxz[m_iTestTimes_BzYxz-1]*100;
            if (std::abs(cz)>sysxs)
            {
                for(int i=0;i<m_iTestTimes_BzYxz;i++)
                {
                    m_dblAll_BzYxz[i]=m_dblAll_BzYxz[m_iTestTimes_BzYxz-1];
                }
                tempbzYxz=m_dblAll_BzYxz[m_iTestTimes_BzYxz-1];
                m_iTestTimes_BzYxz=1;
            }
            double tempbcYxz=SZLBA(m_iTestTimes_BcYxz,m_dblAll_BcYxz);
            cz= (m_dblAll_BcYxz[m_iTestTimes_BcYxz-1] - tempbcYxz)/m_dblAll_BcYxz[m_iTestTimes_BcYxz-1]*100;
            if (std::abs(cz)>sysxs)
            {
                for(int i=0;i<m_iTestTimes_BcYxz;i++)
                {
                    m_dblAll_BcYxz[i]=m_dblAll_BcYxz[m_iTestTimes_BcYxz-1];
                }
                tempbcYxz=m_dblAll_BcYxz[m_iTestTimes_BcYxz-1];
                m_iTestTimes_BcYxz=1;
            }
            /*
            double tempbzXw=SZLBA(m_iTestTimes_BzXw,m_dblAll_BzXw);
            cz= m_dblAll_BzXw[m_iTestTimes_BzXw-1] - tempbzXw;
            if (std::abs(cz)>sysjc)
            {
                for(int i=0;i<m_iTestTimes_BzXw;i++)
                {
                    m_dblAll_BzXw[i]=m_dblAll_BzXw[m_iTestTimes_BzXw-1];
                }
                tempbzXw=m_dblAll_BzXw[m_iTestTimes_BzXw-1];
                m_iTestTimes_BzXw=1;
            }
            double tempbcXw=SZLBA(m_iTestTimes_BcXw,m_dblAll_BcXw);
            cz= m_dblAll_BcXw[m_iTestTimes_BcXw-1] - tempbcXw;
            if (std::abs(cz)>sysjc)
            {
                for(int i=0;i<m_iTestTimes_BcXw;i++)
                {
                    m_dblAll_BcXw[i]=m_dblAll_BcXw[m_iTestTimes_BcXw-1];
                }
                tempbcXw=m_dblAll_BcXw[m_iTestTimes_BcXw-1];
                m_iTestTimes_BcXw=1;
            }
        */
            dblYXZ_HGQ=tempbcYxz;
            dblYXZ_JYY=tempbzYxz;
        ////    dblXW_HGQ=tempbcXw;
        ////    dblXW_JYY=tempbzXw;
            if (newTestPage->cboBcSelect->currentIndex()==5)  //数字量时补偿方法不同
            {
                dblXW_JYY += jcdata[0];
                if (dblYXZ_JYY<2.0)
                    dblXW_JYY +=jcdata[1];
                else if (dblYXZ_JYY<10.0)
                    dblXW_JYY +=jcdata[2];
                else
                    dblXW_JYY +=jcdata[3];
            }

            m_dblBC = (dblYXZ_HGQ - dblYXZ_JYY) / dblYXZ_JYY * 100;
            m_dblJC = dblXW_HGQ - dblXW_JYY;
            if (m_dblJC>180*60)
                m_dblJC -= 360*60;
            else if (m_dblJC<-180*60)
                m_dblJC += 360*60;

            //补偿=总体补偿+分段补偿
            m_dblBC +=bcdata[0];
            if (dblYXZ_JYY<2.0)
                m_dblBC +=bcdata[1];
            else if (dblYXZ_JYY<10.0)
                m_dblBC +=bcdata[2];
            else
                m_dblBC +=bcdata[3];
            if (newTestPage->cboBcSelect->currentIndex()!=5)  //数字量时补偿方法不同
            {
                m_dblJC +=jcdata[0];
                if (dblYXZ_JYY<2.0)
                    m_dblJC +=jcdata[1];
                else if (dblYXZ_JYY<10.0)
                    m_dblJC +=jcdata[2];
                else
                    m_dblJC +=jcdata[3];
            }

            m_dblAll_BC[m_iTestTimes_Bc]=m_dblBC;
            m_dblAll_JC[m_iTestTimes_Jc]=m_dblJC;
            m_iTestTimes_Bc++;
            m_iTestTimes_Jc++;

            m_dblBC=SZLB(m_iTestTimes_Bc,m_dblAll_BC);
            m_dblJC=SZLB(m_iTestTimes_Jc,m_dblAll_JC);

           if (m_iTestTimes_Bc>=m_iAvgNum)
            {
                for(int i=0;i<m_iTestTimes_Bc-1;i++)
                {
                    m_dblAll_BC[i]=m_dblAll_BC[i+1];
                }
                m_iTestTimes_Bc--;
            }
            if (m_iTestTimes_Jc>=m_iAvgNum)
            {
                for(int i=0;i<m_iTestTimes_Jc-1;i++)
                {
                    m_dblAll_JC[i]=m_dblAll_JC[i+1];
                }
                m_iTestTimes_Jc--;
            }
            if (m_iTestTimes_BzYxz>=10)//定为10次   m_iAvgNum
            {
                for(int i=0;i<m_iTestTimes_BzYxz-1;i++)
                {
                    m_dblAll_BzYxz[i]=m_dblAll_BzYxz[i+1];
                }
                m_iTestTimes_BzYxz--;
            }
            if (m_iTestTimes_BcYxz>=10)//定为10次   m_iAvgNum
            {
                for(int i=0;i<m_iTestTimes_BcYxz-1;i++)
                {
                    m_dblAll_BcYxz[i]=m_dblAll_BcYxz[i+1];
                }
                m_iTestTimes_BcYxz--;
            }
            if (m_iTestTimes_BzXw>=10)
            {
                for(int i=0;i<m_iTestTimes_BzXw-1;i++)
                {
                    m_dblAll_BzXw[i]=m_dblAll_BzXw[i+1];
                }
                m_iTestTimes_BzXw--;
            }
            if (m_iTestTimes_BcXw>=10)
            {
                for(int i=0;i<m_iTestTimes_BcXw-1;i++)
                {
                    m_dblAll_BcXw[i]=m_dblAll_BcXw[i+1];
                }
                m_iTestTimes_BcXw--;
            }
        }
        else
        {
            if (newTestPage->cboBcSelect->currentIndex()==5)  //数字量时补偿方法不同
            {
                dblXW_JYY += jcdata[0];
                if (dblYXZ_JYY<2.0)
                    dblXW_JYY +=jcdata[1];
                else if (dblYXZ_JYY<10.0)
                    dblXW_JYY +=jcdata[2];
                else
                    dblXW_JYY +=jcdata[3];
            }
            m_dblYXZ_HGQ=dblYXZ_HGQ;
            m_dblYXZ_JYY=dblYXZ_JYY;
            m_dblXW_HGQ=dblXW_HGQ;
            m_dblXW_JYY=dblXW_JYY;
            m_dblBC = (dblYXZ_HGQ - dblYXZ_JYY) / dblYXZ_JYY * 100;
            m_dblJC = dblXW_HGQ - dblXW_JYY;
            if (m_dblJC>180*60)
                m_dblJC -= 360*60;
            else if (m_dblJC<-180*60)
                m_dblJC += 360*60;
            //补偿=总体补偿+分段补偿
            m_dblBC +=bcdata[0];
            if (dblYXZ_JYY<2.0)
                m_dblBC +=bcdata[1];
            else if (dblYXZ_JYY<10.0)
                m_dblBC +=bcdata[2];
            else
                m_dblBC +=bcdata[3];
            if (newTestPage->cboBcSelect->currentIndex()!=5)  //数字量时补偿方法不同
            {
                m_dblJC +=jcdata[0];
                if (dblYXZ_JYY<2.0)
                    m_dblJC +=jcdata[1];
                else if (dblYXZ_JYY<10.0)
                    m_dblJC +=jcdata[2];
                else
                    m_dblJC +=jcdata[3];
            }
        }
    }
    else
    {
        if (newTestPage->cboBcSelect->currentIndex()==5)  //数字量时补偿方法不同
        {
            dblXW_JYY += jcdata[0];
            if (dblYXZ_JYY<2.0)
                dblXW_JYY +=jcdata[1];
            else if (dblYXZ_JYY<10.0)
                dblXW_JYY +=jcdata[2];
            else
                dblXW_JYY +=jcdata[3];
        }
        m_dblBC = (dblYXZ_HGQ - dblYXZ_JYY) / dblYXZ_JYY * 100;
        m_dblJC = dblXW_HGQ - dblXW_JYY;
        if (m_dblJC>180*60)
            m_dblJC -= 360*60;
        else if (m_dblJC<-180*60)
            m_dblJC += 360*60;
        //补偿=总体补偿+分段补偿
        m_dblBC +=bcdata[0];
        if (dblYXZ_JYY<2.0)
            m_dblBC +=bcdata[1];
        else if (dblYXZ_JYY<10.0)
            m_dblBC +=bcdata[2];
        else
            m_dblBC +=bcdata[3];
        if (newTestPage->cboBcSelect->currentIndex()!=5)  //数字量时补偿方法不同
        {
            m_dblJC +=jcdata[0];
            if (dblYXZ_JYY<2.0)
                m_dblJC +=jcdata[1];
            else if (dblYXZ_JYY<10.0)
                m_dblJC +=jcdata[2];
            else
                m_dblJC +=jcdata[3];
        }
    }

    m_dblYXZ_HGQ = dblYXZ_HGQ;
    m_dblYXZ_JYY = dblYXZ_JYY;
    m_dblXW_HGQ = dblXW_HGQ;
    m_dblXW_JYY = dblXW_JYY;
    if(dblYXZ_HGQ == 0 || dblYXZ_JYY == 0)
    {
            return false;
    }else
    {
            m_iTestTimes++;
            return true;
    }
}

void MainWindow::flushBuff()
{
    bool b=cappacket->getIsOK();
 //   qDebug()<<b;
    if (b)
    {
     //   qDebug()<<"1:"<<cappacket->m_PointArray[7][10];
 ////       update();
    //    qDebug()<<"4:"<<cappacket->m_PointArray[7][10];
        cappacket->setIsOK(false);
        if(iTestMode==2)
            cappacket->StopCap(true);
    }
}


void MainWindow::settempbuff()
{
    //Sync(cappacket->getSync());
 //   sigBeginSync(cappacket->getSync());

    syncFlag=cappacket->getSync();
    bStart=false;
    m_MaxSZL=cappacket->getMaxShuZiLiang();
    /*
    for(int j=0;j<12;j++)
    {
        for(int i=0;i<iZHOUQI*200;i++)
        {
            tempbuff[j][i]=buf[j][i];
        }
    }
    */
    if (bwFlag==1)          //仅用于显示谐波，不显示图像
    {
        writeXBdata(0);
    }
    else
    {
        bStart=true;
    }

    if(iTestMode == 2)
    {
        luboIsEnd = true;
    }

    memset(maxInChanel,0x00,sizeof(maxInChanel));

    qDebug()<<"settembuff, sigcyOver() is rcved!";
    update();
}

void MainWindow::openPWM()
{
    pwmfd=open("/dev/pwm",0);
    if (pwmfd<0)
    {
     //   QMessageBox::information(NULL,tr("错误"),tr("打开pwm设备出错！"));
        myHelper::ShowMessageBoxError(tr("打开pwm设备出错！"));
    }
   // ioctl(pwmfd,1,2000); //蜂鸣器叫

}
void MainWindow::closePWM()
{
    ::close(pwmfd);
}

void MainWindow::writeXBdata(int flag)
{
    QString s="2b";
    QModelIndex index = newBwjyPage->modelTd->index(1,1,QModelIndex());
    int icol =newBwjyPage->cboTdh->currentText().toInt()-1;
    int iXb=newBwjyPage->cboXieboNum->currentText().toInt()-1;
    double allYxz=0;
    if (flag==0)
    {
        for(int j=0;j<=iXb+1;j++)
        {
            GetYXZ_XieBo(icol,j);
        }
    }
    for(int j=0;j<iXb+2;j++)
    {
        if (flag==0)
        {
            double xb1=100;             //基波

            if(j == 0)
            {
                xb1=dblxbYXZ[0]/dblxbYXZ[1]*100;        //直流
                index = newBwjyPage->modelTd->index(0,j,QModelIndex());
                newBwjyPage->modelTd->setData(index,QString::number(xb1,'f',3));
                s += ":" + QString::number(xb1,'f',3);
            }
            else if(j == 1)
            {
                index = newBwjyPage->modelTd->index(0,j,QModelIndex());
                newBwjyPage->modelTd->setData(index,QString::number(xb1,'f',3));
                s += ":" + QString::number(xb1,'f',3);
            }
            if(j > 1)
            {
                double xb=dblxbYXZ[j]/dblxbYXZ[1]*100;//double xb=dblxbYXZ[j+2]/allYxz*100;
                allYxz += xb * xb;
                index = newBwjyPage->modelTd->index(0,j,QModelIndex());
                newBwjyPage->modelTd->setData(index,QString::number(xb,'f',3));
                s += ":" + QString::number(xb,'f',3);
            }
        }
        else
        {
            index = newBwjyPage->modelTd->index(0,j,QModelIndex());
            newBwjyPage->modelTd->setData(index,"");
        }
    }
    if (flag==0)
    {
        double xbhyl=std::sqrt(allYxz);
        newBwjyPage->txtXbHyl->setText(QString::number(xbhyl,'f',3));
        s += ":" + QString::number(xbhyl,'f',3);
    }

    if(m_bIsConn)
    {
        tcpServer->TcpSend(s);
    }
}
void MainWindow::GetYXZ_XieBo(int iChannel, int iCiShu)
{
        if(iChannel >=12) return;
        double dblSin = 0, dblCos = 0, dblYXZ = 0;
        int iSmpRate=cappacket->SmpRate();
        double iFuZhi=cappacket->FuZhi();
        for(int i = 0; i < iSmpRate * iZHOUQI; i++)
        {
                dblSin += 2 / (double)iSmpRate * ((double)cappacket->m_PointArray[iChannel][i] ) * std::sin(2 * PI * i * iCiShu / iSmpRate);
                dblCos += 2 / (double)iSmpRate * ((double)cappacket->m_PointArray[iChannel][i] ) * std::cos(2 * PI * i * iCiShu / iSmpRate);
        }
        dblYXZ = std::sqrt((dblSin * dblSin + dblCos * dblCos) / 2) / iZHOUQI * 1000/ iFuZhi;
        dblxbYXZ[iCiShu]=dblYXZ;
}

void MainWindow::showXiebonum()
{
    int i=newBwjyPage->cboXieboNum->currentText().toInt()-1;
    newBwjyPage->xiebonum(i);
    if (i>13)
       i=13;
    int iwidth=(i-4)*65;
    newBwjyPage->tabTd->setMinimumWidth(390+iwidth);
    newBwjyPage->tabTd->setMaximumWidth(390+iwidth);

}
void MainWindow::toUpdate()
{
    QString sfile;
    QString dfile;
    QDir dir;
    sfile=tr("/udisk/pcaptest");
    dfile=tr("/opt/myapp/pcaptest");

    if (!QFile::exists(sfile))
    {
        QString s=tr("找不到更新文件:");
        s+=sfile;
      //  QMessageBox::information(NULL,tr("错误"),s);
        myHelper::ShowMessageBoxError(s);
        return;
    }
    QDir *createfile = new QDir;
    bool exist = createfile->exists(dfile);
    if (exist)
    {
        createfile->remove(dfile);
    }
    if(!QFile::copy(sfile, dfile))
    {
      //  QMessageBox::information(NULL,tr("错误"),tr("更新文件出错!"));
        myHelper::ShowMessageBoxError(tr("更新文件出错!"));
        return;
    }
   // QMessageBox::information(NULL,tr("更新文件"),tr("更新文件成功,请重新启动程序！"));
    myHelper::ShowMessageBoxError(tr("更新文件成功,请重新启动程!"));
}
double MainWindow::TransSZLToValue_CT(double dSZL)
{
    double dRes;
    QString sYc=newTestPage->txtEdyc->text();
    if(guiyue==GuiYue9_1)
        dRes = dSZL / 11585 * sYc.toDouble() / std::sqrt(2);
    else
        dRes = dSZL / 1000;
    return dRes;
}

double MainWindow::TransSZLToValue_PT(double dSZL)
{
    double dRes,dEDYC;
    QString sYc=newTestPage->txtEdyc->text();
    dEDYC = sYc.toDouble();
    if (newTestPage->cboEdycDw->currentIndex()==1)
    {
        dEDYC = dEDYC / std::sqrt(3);
    }
    if(guiyue==GuiYue9_1)
        dRes = dSZL / 11585 * dEDYC / std::sqrt(2);
    else
        dRes = dSZL / 100000;
    return dRes;
}
void MainWindow::startAll()
{
  //  timer->start(500);
    showAllTimer->stop();
   // bool allOK=true;
    if (!cappacket->IsOpen())
    {
        cappacket->StopCap(false);
        openNetFlag=cappacket->Open(newTestPage->cboCyfs->currentIndex());
        openNetTimer->start(1000);
    }
    if (openNetFlag)
    {
        openNetFlag=false;
        openNetTimer->stop();
        cappacket->setTestType(1);
        cappacket->StopCap(false);
        cappacket->setMacGl(1);
        cappacket->start();
    }
    else
    {
        newSclPage->labInfo->setText(tr("初始化失败！"));
    }
}
void MainWindow::allPage()
{
    if(nowtest==1)
    {
        m_zqgs=1;
        newAllPage->setTDH(newTestPage->f_wcPage->cboBctd->currentIndex());
        pagesWidget->setCurrentIndex(1);
        // pagesWidget->setVisible(true);
        // cappacket->StopCap(true);
        iTestMode=3;    //全帧解析

//        if (!cappacket->IsOpen())
//        {
//            cappacket->StopCap(false);
//            openNetFlag=cappacket->Open(newTestPage->cboCyfs->currentIndex());
//            openNetTimer->start(1000);

//            if(!openNetFlag)
//            {
//                showAllTimer->stop();
//              //  QMessageBox::information(NULL,"初始化结果","初始化失败！");
//                myHelper::ShowMessageBoxError(tr("初始化失败！"));
//                return;
//            }
//            else
//            {
//                openNetTimer->stop();
//                openNetFlag=false;
//            }
//        }

        dblFuZhi_HGQ=11585;

        guiyue=m_clnp->recvThread->GuiYueType();
        f_setCSCS();
        m_iPeriodCnt=1;
        m_dblShowPeriods = m_iPeriodCnt;
        //m_clnp->recvThread->SetCapParamater(TestChannel_LuBo,m_iPeriodCnt,0,11585);
        for(int i=0;i<12;i++)
           m_clnp->recvThread->SetChannelShow(i,true);
        m_clnp->recvThread->setIsOK(false);
         m_clnp->recvThread->setMacGl(1);
        //cappacket->start();
         m_clnp->recvThread->start();
    }
    else
    {
        m_zqgs=1;
        newAllPage->setTDH(newTestPage->cboBctd->currentIndex());
        pagesWidget->setCurrentIndex(1);
     //   pagesWidget->setVisible(true);

        iTestMode=3;    //全帧解析

        if (!cappacket->IsOpen())
        {
            cappacket->StopCap(false);
            openNetFlag=cappacket->Open(newTestPage->cboCyfs->currentIndex());
            openNetTimer->start(1000);

            if(!openNetFlag)
            {
                showAllTimer->stop();
              //  QMessageBox::information(NULL,"初始化结果","初始化失败！");
                myHelper::ShowMessageBoxError(tr("初始化失败！"));
                return;
            }
            else
            {
                openNetTimer->stop();
                openNetFlag=false;
            }
        }

        dblFuZhi_HGQ=11585;

        guiyue=cappacket->GuiYueType();
        //setCSCS();
        cappacket->setTestType('S');
        m_iPeriodCnt=1;
        m_dblShowPeriods = m_iPeriodCnt;
        cappacket->SetCapParamater(1,m_iPeriodCnt,0,11585);
        for(int i=0;i<12;i++)
           cappacket->SetChannelShow(i,true);
        cappacket->setIsOK(false);
        cappacket->setMacGl(1);
        cappacket->start();

        cappacket->StopCap(false);
    }

}

void MainWindow::PrePage()
{
 //   for(int i=0;i<12;i++)
 //       newAllPage->widget[i]->repaint();
    int tdh = getTdh();

    if (tdh>12) tdh -= 12;

    if(newTestPage->tabwc->currentIndex() ==1)//LM  非同步测量
    {
        newTestPage->f_wcPage->cboBctd->setCurrentIndex(tdh);
        newAllPage->setTDH(tdh);
        f_setCSCS();
    }
    else
    {
        newTestPage->cboBctd->setCurrentIndex(tdh);
        newAllPage->setTDH(tdh);
        setCSCS();
    }

}

void MainWindow::NextPage()
{
    int tdh=getTdh();
    if (tdh<96)
        tdh+=12;
    if(newTestPage->tabwc->currentIndex() ==1)//LM  非同步测量
    {
        newTestPage->f_wcPage->cboBctd->setCurrentIndex(tdh);
        newAllPage->setTDH(tdh);
        f_setCSCS();
    }
    else
    {
        newTestPage->cboBctd->setCurrentIndex(tdh);
        newAllPage->setTDH(tdh);
        setCSCS();
    }
}

int MainWindow::getTdh()
{
    QString ms=newAllPage->labTd[0]->text();
    char charSplit=':';
    QStringList stdh=ms.split(charSplit);
    ms=stdh.at(1);
    return ms.toInt();
}

void MainWindow::addList(QString app,QString mac,QString type,int cypl,int asdu)
{
    cypl+=1;

    if (cypl < 4001)
    {
        cypl = 4000;
    }
    else if(cypl < 12801)
    {
        cypl = 12800;
    }

    QStandardItem *item0=new QStandardItem();
    item0->setTextAlignment(Qt::AlignCenter);
    QStandardItem *item1=new QStandardItem();
    item1->setTextAlignment(Qt::AlignCenter);
    QStandardItem *item2=new QStandardItem();
    item2->setTextAlignment(Qt::AlignCenter);
    QStandardItem *item3=new QStandardItem();
    item3->setTextAlignment(Qt::AlignCenter);
    QStandardItem *item4=new QStandardItem();
    item4->setTextAlignment(Qt::AlignCenter);
    QStandardItem *item5=new QStandardItem();
    item5->setTextAlignment(Qt::AlignCenter);
    QModelIndex index;
    int irowCount=newSclPage->tabScl->model()->rowCount();

    if (irowCount>0)
    {
        for(int i=0;i<irowCount;i++)
        {
            index=newSclPage->tabScl->model()->index(i,1,QModelIndex());
            QString tempapp=index.data().toString();
            index=newSclPage->tabScl->model()->index(i,2,QModelIndex());
            QString tempmac=index.data().toString();
            if ((tempapp==app)&&(tempmac==mac))
            {
                index=newSclPage->tabScl->model()->index(i,4,QModelIndex());  //cypl
                int tempcypl=index.data().toInt();

            //    qDebug()<<tempcypl<<" "<<cypl;
                if (tempcypl < cypl)
                    newSclPage->tabScl->model()->setData(index,QString::number(cypl));
                return;
            }
        }
    }

    item0->setText(QString::number(irowCount+1));
    item1->setText(app);
    item2->setText(mac);
    item3->setText(type);
    item4->setText(QString::number(cypl));
    item5->setText(QString::number(asdu));
    QList<QStandardItem*> item;
    item << item0<< item1<< item2<< item3<< item4<< item5;
    model->appendRow(item);
    newSclPage->tabScl->setModel(model);
    newSclPage->tabScl->selectRow(0);
}

void MainWindow::showAllMMS()
{   
    QStandardItemModel *model=new QStandardItemModel(0,5);
    model->setHeaderData(0,Qt::Horizontal,tr("序号"));
    model->setHeaderData(1,Qt::Horizontal,tr("APPID"));
    model->setHeaderData(2,Qt::Horizontal,tr("MAC"));
    model->setHeaderData(3,Qt::Horizontal,tr("采样频率"));
    model->setHeaderData(4,Qt::Horizontal,tr("ASDU数目"));
    int tm=reader.PSUB.length();
    if (tm>0)
    {
        int mIndex=1;
        for(int i=0;i<tm;i++)
        {
            QString s=reader.PSUB[i].add.APPID;
            if (!s.isEmpty())
            {
                QStandardItem *item0=new QStandardItem();
                QStandardItem *item1=new QStandardItem();
                QStandardItem *item2=new QStandardItem();
                QStandardItem *item3=new QStandardItem();
                QStandardItem *item4=new QStandardItem();
                item0->setText(QString::number(mIndex));
                item1->setText(s);
                s=reader.PSUB[i].add.MAC;
                item2->setText(s);
                s=reader.PSUB[i].add.smpRate;
                int ms=s.toInt()*50;
                item3->setText(QString::number(ms));
                s=reader.PSUB[i].add.asdu;
                item4->setText(s);
                QList<QStandardItem*> item;
                item << item0<< item1<< item2<< item3<< item4;
                model->appendRow(item);

                mIndex++;
            }
        }
    }

    newSclPage->tabScl->setModel(model);
    newSclPage->tabScl->setColumnWidth(0,50);
    newSclPage->tabScl->setColumnWidth(1,80);
    newSclPage->tabScl->setColumnWidth(2,190);
    newSclPage->tabScl->setColumnWidth(3,100);
    newSclPage->tabScl->setColumnWidth(4,90);
    if (tm>0)
    {
        QModelIndex index=newSclPage->tabScl->model()->index(0,0,QModelIndex());
        newSclPage->tabScl->setCurrentIndex(index);
        addTdh();
    }
    else
    {
        newSclPage->labTdh->setVisible(false);
        newSclPage->cboTdh->setVisible(false);
        newSclPage->labInfo->setText(tr("无SMV配置项"));
    }
}

void MainWindow::saveMuinfo()
{
    if ((CYPL.toInt()==0)||(CYPL.isEmpty()))
    {
    //    QMessageBox::information(NULL,tr("错误"),tr("采样频率必须为大于0的数字"));
        myHelper::ShowMessageBoxError(tr("采样频率必须为大于0的数字"));
        return;
    }
    QString sql="update muinfo set appid='";
    sql += APPID +"',mac='";
    sql += MAC +"',cypl='";
    sql += CYPL +"',asdu='" ;
    sql += ASDU +"'";
    tbWcxx=myDB->openWcxxforSql(sql);
    tbWcxx.clear();
  //  labInfo->setText(tr("数据已保存!"));
  //  showInfoTimer->start(2000);
}
void MainWindow::addTdh()
{
    if (newSclPage->tabScl->model()->columnCount()==5)          //scl
    {
        newSclPage->cboTdh->clear();
        QModelIndex index=newSclPage->tabScl->currentIndex();
        int irow=index.row();
        if (irow>=0)
        {
            int tds=reader.PSUB[irow].num;

            for(int i=0;i<tds;i++)
            {
                QString in="通道";
                in +=QString::number(i+1);
                in +="[";
                in +=reader.PSUB[irow].fc[i].desc;//LN描述;;;//DOI描述 reader.PSUB[irow].fc[i].doi;
                in +="]";
                newSclPage->cboTdh->addItem(in);
            }

        }

    }
}

void MainWindow::showSclInfo()
{
    QFont font;
    font.setPointSize(12);
    font.setBold(true);
    btnFlag=201;
    QModelIndex index=newSclPage->tabScl->currentIndex();
    int irow=index.row();
    if (irow>=0)
    {
     //   btn2->setVisible(false);
     //   btn1->setVisible(false);
        newSclPage->tabScl->setVisible(false);
        newSclPage->tabSclInfo->setVisible(true);
        int tds=reader.PSUB[irow].num;
        QStandardItemModel *model=new QStandardItemModel(0,5);
        model->setHeaderData(0,Qt::Horizontal,tr("序号"));
        model->setHeaderData(1,Qt::Horizontal,tr("通道类型"));
        model->setHeaderData(2,Qt::Horizontal,tr("相别"));
        model->setHeaderData(3,Qt::Horizontal,tr("LN描述"));
        model->setHeaderData(4,Qt::Horizontal,tr("DOI描述"));
        for(int i=0;i<tds;i++)
        {
            QStandardItem* item0=new QStandardItem();
            item0->setFont(font);
            item0->setTextAlignment(Qt::AlignCenter);
            item0->setText(QString::number(i+1));

            QStandardItem* item3=new QStandardItem();       //LN描述
            item3->setFont(font);
            item3->setTextAlignment(Qt::AlignLeft);
            QString s=reader.PSUB[irow].fc[i].desc;
            item3->setText(s);

            QStandardItem* item1=new QStandardItem();       //通道类型
            item1->setFont(font);
            item1->setTextAlignment(Qt::AlignCenter);
            if (s.isEmpty())
                s=tr("时间");
            else
            {
                if(s.contains("电流")>0)
                    s=tr("电流");
                else if (s.contains("电压")>0)
                    s=tr("电压");
            }
            item1->setText(s);

            QStandardItem* item2=new QStandardItem();       //相别
            item2->setFont(font);
            item2->setTextAlignment(Qt::AlignCenter);
            s=reader.PSUB[irow].fc[i].desc;
            if (s=="")
                s=tr("--");
            else
            {
                if((s.contains("A相")>0)||(s.contains("Ａ相"))>0)
                    s=tr("A相");
                else if ((s.contains("B相")>0)||(s.contains("Ｂ相"))>0)
                    s=tr("B相");
                else if ((s.contains("C相")>0)||(s.contains("Ｃ相"))>0)
                    s=tr("C相");
                else if (s.contains("零序")>0)
                    s=tr("N相");
                else
                    s=tr("X相");
            //    else if (s.contains("间隙")>0)
            //        s=tr("X相");
            //    else if (s.contains("进线")>0)
           //         s=tr("X相");

            }
            item2->setText(s);

            QStandardItem* item4=new QStandardItem();       //DOI描述
            item4->setFont(font);
            item4->setTextAlignment(Qt::AlignLeft);
            s=reader.PSUB[irow].fc[i].doi;
            item4->setText(s);
            if (item2->text().isEmpty())
            {
                QString sa="";
                if((s.contains("A相")>0)||(s.contains("Ａ相"))>0)
                    sa=tr("A相");
                else if ((s.contains("B相")>0)||(s.contains("Ｂ相"))>0)
                    sa=tr("B相");
                else if ((s.contains("C相")>0)||(s.contains("Ｃ相"))>0)
                    sa=tr("C相");
                else if (s.contains("零序")>0)
                    sa=tr("N相");
                else if (s.contains("间隙")>0)
                    sa=tr("X相");
                else if (s.contains("进线")>0)
                    sa=tr("X相");
                item2->setText(sa);
            }
            QList<QStandardItem*> item;
            item << item0<<item1<<item2<<item3<<item4;
            model->appendRow(item);
        }
        newSclPage->tabSclInfo->setModel(model);
        newSclPage->tabSclInfo->setColumnWidth(0,50);
        newSclPage->tabSclInfo->setColumnWidth(1,100);
        newSclPage->tabSclInfo->setColumnWidth(2,80);
        newSclPage->tabSclInfo->setColumnWidth(3,170);
        newSclPage->tabSclInfo->setColumnWidth(4,180);
    }
}

void MainWindow::showEdit(QModelIndex index)
{
    int icol=index.column();
    if (icol==0)
    {
        newSysPage->labBcbc->setText("");
        newSysPage->txtBcbc->setVisible(false);
        newSysPage->btnBc->setVisible(false);
        return;
    }
    newSysPage->labBcbc->setText(tr("修改后请按保存"));
    newSysPage->txtBcbc->setText(index.data().toString());
    newSysPage->txtBcbc->setVisible(true);
    newSysPage->btnBc->setVisible(true);
}
void MainWindow::tabSysChanged()
{
    newSysPage->labBcbc->setText("");
    newSysPage->txtBcbc->setVisible(false);
    newSysPage->btnBc->setVisible(false);
}
void MainWindow::saveWcbc()
{
 //   QModelIndex index=newSysPage->tabCsbc->currentIndex();
 //   newSysPage->model->setData(index,newSysPage->txtBcbc->text());
    QString sql;
    if (newSysPage->tabSys->currentIndex()==0)
    {
    sql="update wcbc set ";
    sql += "bc='"+newSysPage->txtbc->text() +"'";
    sql += ",bc1='"+newSysPage->txtbc1->text() +"'";
    sql += ",bc2='"+newSysPage->txtbc2->text() +"'";
    sql += ",bc3='"+newSysPage->txtbc3->text() +"'";
    sql += ",jc='"+newSysPage->txtjc->text() +"'";
    sql += ",jc1='"+newSysPage->txtjc1->text() +"'";
    sql += ",jc2='"+newSysPage->txtjc2->text() +"'";
    sql += ",jc3='"+newSysPage->txtjc3->text() +"'";

    QString wz="";
    if (newSysPage->cboBzbc->currentIndex()==0)
        wz="00";
    else if (newSysPage->cboBzbc->currentIndex()==1)
        wz="11";
    else if (newSysPage->cboBzbc->currentIndex()==2)
        wz="04";
    else if (newSysPage->cboBzbc->currentIndex()==3)
        wz="14";
    else if (newSysPage->cboBzbc->currentIndex()==4)
        wz="24";
    else if (newSysPage->cboBzbc->currentIndex()==5)
        wz="44";
    else if (newSysPage->cboBzbc->currentIndex()==6)
        wz="05";
    else if (newSysPage->cboBzbc->currentIndex()==7)
        wz="15";
    else if (newSysPage->cboBzbc->currentIndex()==8)
        wz="25";
    else if (newSysPage->cboBzbc->currentIndex()==9)
        wz="45";
    else if (newSysPage->cboBzbc->currentIndex()==10)
        wz="22";
    else if (newSysPage->cboBzbc->currentIndex()==11)
        wz="33";
    sql += " where type='" + wz +"'";

    }
    else if(newSysPage->tabSys->currentIndex()==1)
    {

        sql ="update S_XTCS set ";
        sql+="cslx='"+newSysPage->txtSysXs->text() +"'";            //测量类型改为系统系数;
        sql+=",lubo_net_port='"+newSysPage->txtSysBc->text()+"'";            //测量类型改为系统比差系数;
        sql+=",lubo_zhouqi_cnt='"+newSysPage->txtSysJc->text()+"'";            //测量类型改为系统角差系数;
        sql+=",is_com_jyy='"+QString::number(newSysPage->cboDatatime->currentIndex())+"'";
        sql+=",bjcs='"+QString::number(newSysPage->cboSysSf->currentIndex())+"'";

    }
//    qDebug()<<sql;
    QSqlQuery temp=myDB->openWcxxforSql(sql);
    temp.clear();

    labInfo->setText(tr("数据已保存"));
    widgetInfo->show();
    showInfoTimer->start(2000);

}

void MainWindow::mouseReleaseEvent(QMouseEvent *e)//释放
{
    this->mousePos = e->globalPos();
    fdjTimer->stop();
    pt.hide();
    mousePressed = false;   
}
void MainWindow::mousePressEvent(QMouseEvent *e)  //按下
{
    fdjTimer->start(1000);
    this->windowPos = this->pos();  // pos()是相对于窗口的，以窗口左上角为原点（去除边框）。即pos()给出的是一个相对位置坐标。而globalPos(),给出的是一个绝对坐标。
    this->mousePos = e->globalPos();  //    globalpos()给出的坐标信息是相对于桌面的，即以桌面左上角为原点
    this->dPos = mousePos - windowPos;
    if (e->button() == Qt::LeftButton) {
        mousePressed = true;
        mousePoint = e->globalPos() - this->pos();
        e->accept();
    }
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
 //   pt.move(e->globalPos() - this->dPos);
    QPoint f=e->globalPos();
    if ((f.x()>=820) && (f.y()>=540))
    {
        f.setX(f.x()-225);
        f.setY(f.y()-225);
    }
    else
    {
        f.setX(f.x()+25);
        f.setY(f.y()+25);
    }
    pt.move(f);
}

void MainWindow::fdjTimerOut()
{
    QPoint f=mousePos;
    f.setX(f.x()+25);
    f.setY(f.y()+25);
    pt.move(f);
    pt.show();
    fdjTimer->stop();
}
void MainWindow::setTestText(int flag)
{
    if (flag==0)
    {
        newTestPage->txtBzYxz->setText(tr("0.000000"));
        newTestPage->txtBcYxz->setText(tr("0.000000"));
        newTestPage->txtBzXw->setText(tr("0.00"));
        newTestPage->txtBcXw->setText(tr("0.00"));
        newTestPage->txtBFB->setText(tr("0.00"));
        newTestPage->txtBc->setText(tr("0.0000"));
        newTestPage->txtJc->setText(tr("0.00"));
        newTestPage->txtMaxBc->setText(tr("0.0000"));
        newTestPage->txtMaxJc->setText(tr("0.00"));
        newTestPage->txtMinBc->setText(tr("0.0000"));
        newTestPage->txtMinJc->setText(tr("0.00"));
        newTestPage->txtAvgBc->setText(tr("0.0000"));
        newTestPage->txtAvgJc->setText(tr("0.00"));
    }
    else
    {

        jsMaxMin();
    }

}
void MainWindow::jsMaxMin()
{

}
void MainWindow::changeCyfs()
{
    int icyfs=newTestPage->cboCyfs->currentIndex();
    if (icyfs==0)
    {
        newTestPage->txtMac->setVisible(false);
        newTestPage->labMac->setVisible(false);
        newTestPage->btnGet->setVisible(false);
    }
    else if (icyfs==1)
    {
      //  if (newTestPage->cboCyfs->isVisible())
        if (newTestPage->cboBcSelect->currentIndex()==5)//数字量
        {
            newTestPage->txtMac->setVisible(true);
            newTestPage->labMac->setVisible(true);
            newTestPage->btnGet->setVisible(true);
        }
    }
    if (newTestPage->cboBcSelect->currentIndex()==5)//数字量
    {
        myDB->setCyfs(QString::number(icyfs));
    //    myDB->setXTCS();
    }
}

void MainWindow::setMac()
{

    if(newTestPage->tabwc->currentIndex() == 1) //非同步测量
    {
        btnFlag=1;
        cappacket->StopCap(true);
        if (cappacket->IsOpen())
            cappacket->Close();//关闭网口
        QModelIndex index;
        int irow=newSclPage->tabScl->currentIndex().row();
        if (irow<0)
        {
            newSclPage->hide();
            newTestPage->f_wcPage->widgetWcTxt->setVisible(true);
            return;
        }

        index=newSclPage->tabScl->model()->index(irow,2,QModelIndex());
        if( index.data().toString().size() < 4) return;
        MAC=index.data().toString();

        index=newSclPage->tabScl->model()->index(irow,1,QModelIndex());
        APPID=index.data().toString();

        newTestPage->f_wcPage->txtMac->setText(MAC);
        index=newSclPage->tabScl->model()->index(irow,4,QModelIndex());
        CYPL=index.data().toString();
        index=newSclPage->tabScl->model()->index(irow,5,QModelIndex());
        ASDU=index.data().toString();


    //    pagesWidget->setCurrentIndex(0);
        if (newSclPage->cboTdh->isVisible())
            newTestPage->f_wcPage->cboBctd->setCurrentIndex(newSclPage->cboTdh->currentIndex());
        newSclPage->hide();
        newTestPage->f_wcPage->widgetWcTxt->setVisible(true);
    }
    else
    {
        btnFlag=1;
        cappacket->StopCap(true);
        if (cappacket->IsOpen())
            cappacket->Close();//关闭网口
        QModelIndex index;
        int irow=newSclPage->tabScl->currentIndex().row();
        if (irow<0)
        {
            newSclPage->hide();
            newTestPage->widgetWcTxt->setVisible(true);
            return;
        }

        index=newSclPage->tabScl->model()->index(irow,2,QModelIndex());
        if( index.data().toString().size() < 4) return;
        MAC=index.data().toString();

        index=newSclPage->tabScl->model()->index(irow,1,QModelIndex());
        APPID=index.data().toString();

        newTestPage->txtMac->setText(MAC);
        index=newSclPage->tabScl->model()->index(irow,4,QModelIndex());
        CYPL=index.data().toString();
        index=newSclPage->tabScl->model()->index(irow,5,QModelIndex());
        ASDU=index.data().toString();


    //    pagesWidget->setCurrentIndex(0);
        if (newSclPage->cboTdh->isVisible())
            newTestPage->cboBctd->setCurrentIndex(newSclPage->cboTdh->currentIndex());
        newSclPage->hide();
        newTestPage->widgetWcTxt->setVisible(true);
    }

}

void MainWindow::slotShowList()
{
  //  pagesWidget->setCurrentIndex(6);
  //  btn1->setVisible(true);
  //  btn1->setEnabled(true);
  //  btn1->setText(tr("确定"));
 //   btn2->setVisible(false);
    QFont ft;
    ft.setPixelSize(17);

    newSclPage->labInfo->setText(tr(""));
    newSclPage->labTdh->setVisible(false);
    newSclPage->cboTdh->setVisible(false);
    newSclPage->setGeometry( 600, 440, 580, 300);
    newSclPage->show();

    if(newTestPage->tabwc->currentIndex()==1)//LM非同步测量
    {
        newTestPage->f_wcPage->widgetWcTxt->setVisible(false);
    }
    else
            newTestPage->widgetWcTxt->setVisible(false);

    btnFlag=102;

    model=new QStandardItemModel(0,6);
    model->setHeaderData(0,Qt::Horizontal,tr("序号"));
    model->setHeaderData(1,Qt::Horizontal,tr("APPID"));
    model->setHeaderData(2,Qt::Horizontal,tr("MAC"));
    model->setHeaderData(3,Qt::Horizontal,tr("类型"));
    model->setHeaderData(4,Qt::Horizontal,tr("采样频率"));
    model->setHeaderData(5,Qt::Horizontal,tr("ASDU数目"));

    newSclPage->tabScl->setStyleSheet("font-size:17px;");
    newSclPage->tabScl->setModel(model);
    newSclPage->tabScl->setColumnWidth(0,50);
    newSclPage->tabScl->setColumnWidth(1,60);
    newSclPage->tabScl->setColumnWidth(2,180);
    newSclPage->tabScl->setColumnWidth(3,70);
    newSclPage->tabScl->setColumnWidth(4,80);
    newSclPage->tabScl->setColumnWidth(5,100);

    showAllTimer->start(100);
}

void MainWindow::slotShowScl()
{
    newSclPage->labInfo->setText(tr(""));
    newSclPage->labTdh->setVisible(true);
    newSclPage->cboTdh->setVisible(true);
    newSclPage->cboTdh->clear();
    newSclPage->setGeometry(600,450,550,200);
   // newSclPage->setMaximumWidth(240);
    newSclPage->show();
    if(nowtest ==1)
    {
        newTestPage->f_wcPage->widgetWcTxt->setVisible(false);
    }
    else
            newTestPage->widgetWcTxt->setVisible(false);


    btnFlag=101;
    QString fileName="";
    fileName= QFileDialog::getOpenFileName(this, tr("open file"), " ", tr("sclfile(*.scd *.cid *.icd)"));
    if (fileName=="")
    {
        qDebug()<<"打开配置文件失败!";
        return;
    }
    QFile file(fileName);
    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
      //  ui->radioButton->setChecked(true);
        reader.clear();
        reader.read(&file);
        showAllMMS();
    }
    else
    {
        qDebug()<<"No file to read...";
    }
    file.close();
}

void MainWindow::slotShowMenu(QModelIndex index)
{
    QAction *action1;
    QAction *action2;
    QAction *action3;
    QMenu *menu=new QMenu();
    m_index=index.column();
    if (index.column()==0)
    {
        action1=new QAction(tr("扩展 FT3"),this);
        action2=new QAction(tr("扩展 FT3"),this);
        action3=new QAction(tr(""),this);
        menu->clear();
        menu->addAction(action1);
//        menu->addAction(action2);
    }
    else if(index.column()==1)
    {
        action1=new QAction(tr("4K"),this);
        action2=new QAction(tr("12.8K"),this);
        action3=new QAction(tr(""),this);
        menu->clear();
        menu->addAction(action1);
        menu->addAction(action2);
    }
    else if(index.column()==2)
    {
        QModelIndex indexa = newAddPage->tabInfo->model()->index(0,0,QModelIndex());
        if(indexa.data().toString()=="IEC60044-7/8(FT3)")
        {
            action1=new QAction(tr("2.5M"),this);
            action2=new QAction(tr("5M"),this);
            action3=new QAction(tr("10M"),this);
            menu->clear();
            menu->addAction(action1);
            menu->addAction(action2);
            menu->addAction(action3);
        }
        else
        {
            action1=new QAction(tr("5M"),this);
            action2=new QAction(tr("10M"),this);
            menu->clear();
            menu->addAction(action1);
            menu->addAction(action2);
            action3=new QAction(tr(""),this);
        }
    }
    sName1=action1->text();
    sName2=action2->text();
    sName3=action3->text();
    connect(action1,SIGNAL(triggered()),this,SLOT(slottemp1()));
    connect(action2,SIGNAL(triggered()),this,SLOT(slottemp2()));
    connect(action3,SIGNAL(triggered()),this,SLOT(slottemp3()));
    menu->exec(QCursor::pos());
}

void MainWindow::slottemp1()
{
    QModelIndex indexa;
    if (m_index==0)
    {
        indexa = newAddPage->tabInfo->model()->index(0,0,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName1);
        indexa = newAddPage->tabControl->model()->index(0,9,QModelIndex());

        return;

        if (indexa.data().toString()=="22")
        {
            newAddPage->tabControl->model()->setData(indexa,"12");
            newAddPage->inittabTdinfo(0);
        }
    }
    else if (m_index==1)
    {
        indexa = newAddPage->tabInfo->model()->index(0,1,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName1);

    }
    else if (m_index==2)
    {
        indexa = newAddPage->tabInfo->model()->index(0,2,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName1);
    }
}
void MainWindow::slottemp2()
{
    QModelIndex indexa;
    if (m_index==0)
    {
        indexa = newAddPage->tabInfo->model()->index(0,0,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName2);
        indexa = newAddPage->tabInfo->model()->index(0,2,QModelIndex());
        if (indexa.data().toString()=="2.5M")
            newAddPage->tabInfo->model()->setData(indexa,"5M");
        indexa = newAddPage->tabControl->model()->index(0,9,QModelIndex());
        if (indexa.data().toString()=="12")
        {
            newAddPage->tabControl->model()->setData(indexa,"22");
            newAddPage->inittabTdinfo(1);
        }
    }
    else if (m_index==1)
    {
        indexa = newAddPage->tabInfo->model()->index(0,1,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName2);
    }
    else if (m_index==2)
    {
        indexa = newAddPage->tabInfo->model()->index(0,2,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName2);
    }
}
void MainWindow::slottemp3()
{
    QModelIndex indexa;
    if (m_index==0)
    {
        indexa = newAddPage->tabInfo->model()->index(0,0,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName3);
    }
    else if (m_index==1)
    {
        indexa = newAddPage->tabInfo->model()->index(0,1,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName3);
    }
    else if (m_index==2)
    {
        indexa = newAddPage->tabInfo->model()->index(0,2,QModelIndex());
        newAddPage->tabInfo->model()->setData(indexa,sName3);
    }
}
void MainWindow::loadCfg()
{
//    QString sPath=QCoreApplication::applicationDirPath();
//    QString sfile=sPath +"/"+ tr("Config.ini");
    QString sfile=tr("c://model-1000/Config.ini");
    QString wcPort="0";
    QString muPort="0";
    QString tTime="0";
    QString bcSz="1";
    QString dsTime="10";
    QString ssTime="600";
    QString ccbh="11111111";
    QString hardWare="V3.0";
    QString softWare="V3.0";

    if (!QFile::exists(sfile))
    {
     //   QFile file("Config.ini");
       //     file.open(QIODevice::WriteOnly);
        QSettings *cfgWrite=new QSettings("c://model-1000/Config.ini", QSettings::IniFormat);
        cfgWrite->setValue("/wcTest/inputPort",wcPort);
        cfgWrite->setValue("/muTest/inputPort",muPort);
        cfgWrite->setValue("/muTest/testTime",tTime);
        cfgWrite->setValue("/muTest/bcClock",bcSz);
        cfgWrite->setValue("/muTest/dsTime",dsTime);
        cfgWrite->setValue("/muTest/ssTime",ssTime);
        cfgWrite->setValue("/info/ccbh",ccbh);
        cfgWrite->setValue("/info/hardWare",hardWare);
        cfgWrite->setValue("/info/softWare",softWare);
        delete cfgWrite;
    }
    else
    {
        QSettings *cfgRead = new QSettings("c://model-1000/Config.ini", QSettings::IniFormat);
        wcPort = cfgRead->value("/wcTest/inputPort").toString();
        muPort = cfgRead->value("/muTest/inputPort").toString();
        tTime = cfgRead->value("/muTest/testTime").toString();
        bcSz = cfgRead->value("/muTest/bcClock").toString();
        dsTime = cfgRead->value("/muTest/dsTime").toString();
        ssTime = cfgRead->value("/muTest/ssTime").toString();
        ccbh  = cfgRead->value("/info/ccbh").toString();
        hardWare  = cfgRead->value("/info/hardWare").toString();
        softWare  = cfgRead->value("/info/softWare").toString();

        //etherPortName = cfgRead->value("/wcTest/port").toString();

        delete cfgRead;
    }
    newTestPage->cboInput->setCurrentIndex(wcPort.toInt());
    newBwjyPage->cboInput->setCurrentIndex(muPort.toInt());
    newBwjyPage->cboTime->setCurrentIndex(tTime.toInt());
    newBwjyPage->cboBcsz->setCurrentIndex(bcSz.toInt());
    newBwjyPage->txtDsTime->setText(dsTime);
    newBwjyPage->txtSsTime->setText(ssTime);

    QString temp=tr("出厂编号:") +ccbh;
    newSysPage->labCcbh->setText(temp);
    temp=tr("硬件版本号:") +hardWare;
    newSysPage->labHardware->setText(temp);
    temp=tr("软件版本号:") +softWare;
    newSysPage->labSoftware->setText(temp);
}
void MainWindow::saveCfg()
{
    QString wcPort=QString::number(newTestPage->cboInput->currentIndex());
    QString muPort=QString::number(newBwjyPage->cboInput->currentIndex());
    QString tTime=QString::number(newBwjyPage->cboTime->currentIndex());
    QString bcSz=QString::number(newBwjyPage->cboBcsz->currentIndex());
    QString dsTime=newBwjyPage->txtDsTime->text();
    QString ssTime=newBwjyPage->txtSsTime->text();

    QSettings *cfgWrite=new QSettings("c://model-1000/Config.ini", QSettings::IniFormat);
    cfgWrite->setValue("/wcTest/inputPort",wcPort);
    cfgWrite->setValue("/muTest/inputPort",muPort);
    cfgWrite->setValue("/muTest/testTime",tTime);
    cfgWrite->setValue("/muTest/bcClock",bcSz);
    cfgWrite->setValue("/muTest/dsTime",dsTime);
    cfgWrite->setValue("/muTest/ssTime",ssTime);
    delete cfgWrite;
}
//LM 非同步测量
void MainWindow::f_bzselect()
{
    if ((newTestPage->f_wcPage->cboBzSelect->currentIndex()==4)||(newTestPage->cboBzSelect->currentIndex()==5))
    {
        newTestPage->f_wcPage->txtBzXdy->setVisible(true);
        newTestPage->f_wcPage->labBzXdy->setVisible(true);
    }
    else
    {
        newTestPage->f_wcPage->txtBzXdy->setVisible(false);
        newTestPage->f_wcPage->labBzXdy->setVisible(false);
    }
}
void MainWindow::f_bcselect()
{
    newTestPage->f_wcPage->labCyfs->setVisible(false);
    newTestPage->f_wcPage->cboCyfs->setVisible(false);
    newTestPage->f_wcPage->labMac->setVisible(false);
    newTestPage->f_wcPage->txtMac->setVisible(false);
    newTestPage->f_wcPage->btnGet->setVisible(false);
    newTestPage->btnAll->setVisible(false);
    newTestPage->f_wcPage->labInput->setVisible(false);
    newTestPage->f_wcPage->cboInput->setVisible(false);
    newTestPage->f_wcPage->labInputMethod->setVisible(false);
    if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==4)//模拟小电压
    {
        newTestPage->f_wcPage->txtBcXdy->setVisible(true);
        newTestPage->f_wcPage->labBcXdy->setVisible(true);
        newTestPage->f_wcPage->labBctd->setVisible(false);
        newTestPage->f_wcPage->cboBctd->setVisible(false);
     //   newParaPage->f_wcPage->szlGroup->setVisible(false);
        newTestPage->f_wcPage->labBhCl->setVisible(false);
        newTestPage->f_wcPage->cboBhCl->setVisible(false);
  //      newParaPage->f_wcPage->rdoGC->setVisible(true);
  //      newParaPage->f_wcPage->rdoLL->setVisible(true);
    //    newParaPage->f_wcPage->cboBcSelect->setMaximumWidth(100);
    }
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)//数字量
    {
        newTestPage->f_wcPage->txtBcXdy->setVisible(false);
        newTestPage->f_wcPage->labBcXdy->setVisible(false);
        newTestPage->f_wcPage->labBctd->setVisible(true);
        newTestPage->f_wcPage->cboBctd->setVisible(true);
        newTestPage->f_wcPage->labBhCl->setVisible(false);
        newTestPage->f_wcPage->cboBhCl->setVisible(false);

        newTestPage->f_wcPage->labCyfs->setVisible(true);
        newTestPage->f_wcPage->cboCyfs->setVisible(true);
        newTestPage->f_wcPage->labInput->setVisible(true);
        newTestPage->f_wcPage->labInputMethod->setVisible(true);
       // newTestPage->f_wcPage->cboInput->setVisible(true);

   //     newTestPage->labMac->setVisible(true);
   //     newTestPage->txtMac->setVisible(true);
   //     newTestPage->btnGet->setVisible(true);
        newTestPage->btnAll->setVisible(true);
        newTestPage->f_wcPage->cboPBcSelect->setCurrentIndex(0);
    }
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==6)//FT3
    {
        newTestPage->f_wcPage->txtBcXdy->setVisible(false);
        newTestPage->f_wcPage->labBcXdy->setVisible(false);
        newTestPage->f_wcPage->labBctd->setVisible(true);
        newTestPage->f_wcPage->cboBctd->setVisible(true);
        newTestPage->f_wcPage->labBhCl->setVisible(true);
        newTestPage->f_wcPage->cboBhCl->setVisible(true);
        newTestPage->f_wcPage->cboPBcSelect->setCurrentIndex(1);
    }
    else
    {
        newTestPage->f_wcPage->txtBcXdy->setVisible(false);
        newTestPage->f_wcPage->labBcXdy->setVisible(false);
        newTestPage->f_wcPage->labBctd->setVisible(false);
        newTestPage->f_wcPage->cboBctd->setVisible(false);
        newTestPage->f_wcPage->labBhCl->setVisible(false);
        newTestPage->f_wcPage->cboBhCl->setVisible(false);
    }
}
void MainWindow::f_changeSaveFlag()
{
    if (newTestPage->f_wcPage->cboSave->currentIndex()==0)
    {
    //    newTestPage->f_wcPage->labNum->setVisible(true);
        newTestPage->f_wcPage->txtTestNum->setVisible(true);
     //   newTestPage->f_wcPage->labYanshi->setVisible(false);
    //    newTestPage->f_wcPage->txtYanshi->setVisible(false);
    //    newTestPage->f_wcPage->labYanshiDw->setVisible(false);
    }
    else if (newTestPage->f_wcPage->cboSave->currentIndex()==1)
    {
  //      newTestPage->f_wcPage->labNum->setVisible(true);
        newTestPage->f_wcPage->txtTestNum->setVisible(true);
    //    newTestPage->f_wcPage->labYanshi->setVisible(true);
    //    newTestPage->f_wcPage->txtYanshi->setVisible(true);
    //    newTestPage->f_wcPage->labYanshiDw->setVisible(true);
    }
}
void MainWindow::f_changeset()
{
    if (newTestPage->f_wcPage->cboCTPT->currentIndex()==0)
    {
     //   newTestPage->f_wcPage->labYc->setText(tr("额定一次电流"));
        newTestPage->f_wcPage->txtEdyc->setText(myDB->edyc_dl);
      //  newParaPage->f_wcPage->labYcdw->setText(tr("A"));
        newTestPage->f_wcPage->cboEdycDw->clear();
        newTestPage->f_wcPage->cboEdycDw->setMinimumWidth(50);
        newTestPage->f_wcPage->cboEdycDw->addItem(tr("A"));
        f_changeJD("I");//new LM
        if (myDB->m_CTJD=="")
            newTestPage->f_wcPage->cboJD->setCurrentIndex(1);
        else
        {
            for(int i=0;i<newTestPage->f_wcPage->cboJD->count();i++)
            {
                newTestPage->f_wcPage->cboJD->setCurrentIndex(i);
                if (newTestPage->f_wcPage->cboJD->currentText()==myDB->m_CTJD)
                    break;
            }
        }
    }
    else if (newTestPage->f_wcPage->cboCTPT->currentIndex()==1)
    {
   //     newTestPage->f_wcPage->labYc->setText(tr("额定一次电压"));
        newTestPage->f_wcPage->txtEdyc->setText(myDB->edyc_dy);
      //  newParaPage->f_wcPage->labYcdw->setText(tr("/√3kV"));
        newTestPage->f_wcPage->cboEdycDw->clear();
        newTestPage->f_wcPage->cboEdycDw->setMinimumWidth(100);
        newTestPage->f_wcPage->cboEdycDw->addItem(tr("kV"));
        newTestPage->f_wcPage->cboEdycDw->addItem(tr("/√3kV"));
        newTestPage->f_wcPage->cboEdycDw->setCurrentIndex(1);
        f_changeJD("U");//new LM
        if (myDB->m_PTJD=="")
            newTestPage->f_wcPage->cboJD->setCurrentIndex(1);
        else
        {
            for(int i=0;i<newTestPage->f_wcPage->cboJD->count();i++)
            {
                newTestPage->f_wcPage->cboJD->setCurrentIndex(i);
                if (newTestPage->f_wcPage->cboJD->currentText()==myDB->m_PTJD)
                    break;
            }
        }
    }
}
void MainWindow::f_changeCyfs()
{
    int icyfs=newTestPage->f_wcPage->cboCyfs->currentIndex();
    if (icyfs==0)
    {
        newTestPage->f_wcPage->txtMac->setVisible(false);
        newTestPage->f_wcPage->labMac->setVisible(false);
        newTestPage->f_wcPage->btnGet->setVisible(false);
    }
    else if (icyfs==1)
    {
      //  if (newTestPage->cboCyfs->isVisible())
        if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)//数字量
        {
            newTestPage->f_wcPage->txtMac->setVisible(true);
            newTestPage->f_wcPage->labMac->setVisible(true);
            newTestPage->f_wcPage->btnGet->setVisible(true);
        }
    }
    if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)//数字量
    {
        myDB->setCyfs(QString::number(icyfs));
    //    myDB->setXTCS();
    }
}
void MainWindow::f_saveWcdata()
{
    QString info="";
    if(isSaved)
    {
        QString tbfs=newTestPage->f_wcPage->cboTbfs->currentText();
        QString bzxz=newTestPage->f_wcPage->cboBzSelect->currentText();
        QString edyc="";
        if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==4)
        {
            bzxz+=",";
            bzxz+=newTestPage->f_wcPage->txtBzXdy->text();
            bzxz+="V";
        }
        QString bcxz=newTestPage->f_wcPage->cboBcSelect->currentText();
        if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==4)
        {
            bcxz+=",";
            bcxz+=newTestPage->f_wcPage->txtBzXdy->text();
            bcxz+="V";
        }
        else if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)
        {
            bcxz+=",通道：";
            bcxz+=newTestPage->f_wcPage->cboBctd->currentText();
          //  bcxz+="通道";
            if (newTestPage->f_wcPage->cboCTPT->currentIndex()==0)
            {
                edyc+="I";
                edyc+=newTestPage->f_wcPage->txtEdyc->text();
            }
            else
            {
                edyc+="U";
                edyc+=newTestPage->f_wcPage->txtEdyc->text();
            }
        }
        nowXh=myDB->insertWcxx(tbfs,bzxz,bcxz,edyc);
        isSaved=false;
    }
    if (nowXh=="")
        return;
    QString bcbfd1="";
    QString bzyxz1="";
    QString bcyxz1="";
    QString bc1="";
    QString jc1="";

    bcbfd1=newTestPage->f_wcPage->txtBFB->text();
    bzyxz1=newTestPage->f_wcPage->txtBzYxz->text();
    bcyxz1=newTestPage->f_wcPage->txtBcYxz->text();
    bc1=newTestPage->f_wcPage->txtBc->text();
    jc1=newTestPage->f_wcPage->txtJc->text();
    if (preBFD=="")
    {
        preBFD=newTestPage->f_wcPage->txtBFB->text();
        myDB->insertWcdata(nowXh,preBFD,bcbfd1,bzyxz1,bcyxz1,bc1,jc1);
        info=tr("数据已存储！");
    }
    else
    {
        double bfd=0;
        bfd=std::abs((newTestPage->f_wcPage->txtBFB->text().toDouble()-preBFD.toDouble())/preBFD.toDouble());
        preBFD=newTestPage->f_wcPage->txtBFB->text();
        if (bfd>=0.01)
        {
            myDB->insertWcdata(nowXh,preBFD,bcbfd1,bzyxz1,bcyxz1,bc1,jc1);
            info=tr("数据已存储！");
        }
        else
        {
            myDB->updateWcdata(nowXh,preBFD,bcbfd1,bzyxz1,bcyxz1,bc1,jc1);
            info=tr("数据已覆盖存储！");
        }
    }
    QDateTime qdatetime=QDateTime::currentDateTime();
    QString date=qdatetime.toString("yyyy-MM-dd")+" "+qdatetime.toString("hh:mm:ss");
    myDB->updateWcxxDate(nowXh,date);
    newTestPage->labInfo->setText(info);
    showInfoTimer->start(2000);

}
void MainWindow::f_changeData()
{
    myDB->f_getXTCS();
    newTestPage->f_wcPage->cboBctd->setCurrentIndex(myDB->HGQ_Channel);
    newTestPage->f_wcPage->txtTestNum->setText(QString::number(myDB->m_Bjcs));
    //newTestPage->f_wcPage->txtYanshi->setText(QString::number(myDB->m_Cyys));
    //newTestPage->f_wcPage->cboTbfs->setCurrentIndex(myDB->TBFS);
    newTestPage->f_wcPage->cboBzSelect->setCurrentIndex(myDB->BZXZ);
    newTestPage->f_wcPage->cboBcSelect->setCurrentIndex(myDB->BCXZ);
    newTestPage->f_wcPage->txtBzXdy->setText(myDB->bzxdy);
    newTestPage->f_wcPage->txtBcXdy->setText(myDB->bcxdy);
    newTestPage->f_wcPage->cboCyfs->setCurrentIndex(myDB->m_Cyfs.toInt());

    newTestPage->f_wcPage->txtMac->setText(myDB->m_Mac);

    if(myDB->mCTPT==0)
    {
        newTestPage->f_wcPage->cboCTPT->setCurrentIndex(0);
        newTestPage->f_wcPage->txtEdyc->setText(myDB->edyc_dl);
    }
    else
    {
        newTestPage->f_wcPage->cboCTPT->setCurrentIndex(1);
        newTestPage->f_wcPage->txtEdyc->setText(myDB->edyc_dy);
    }

    f_changeset();
    f_bzselect();
    f_bcselect();
    f_changeCyfs();
//    QString sql="select * from muinfo";
//    tbWcxx=myDB->openWcxxforSql(sql);
//    if (tbWcxx.next())
//    {
//        APPID=tbWcxx.value(0).toString();
//        MAC=tbWcxx.value(1).toString();
//        CYPL=tbWcxx.value(2).toString();
//        ASDU=tbWcxx.value(3).toString();
//    }
//    else
//    {
//        APPID="";
//        MAC="";
//        CYPL="";
//        ASDU="";
//    }
//    tbWcxx.clear();
//    QModelIndex index;
//    index=newSysPage->tabMU->model()->index(0,0,QModelIndex());
//    newSysPage->tabMU->model()->setData(index,APPID);
//    index=newSysPage->tabMU->model()->index(0,1,QModelIndex());
//    newSysPage->tabMU->model()->setData(index,MAC);
//    index=newSysPage->tabMU->model()->index(0,2,QModelIndex());
//    newSysPage->tabMU->model()->setData(index,CYPL);
//    index=newSysPage->tabMU->model()->index(0,3,QModelIndex());
//    newSysPage->tabMU->model()->setData(index,ASDU);

}

void MainWindow::f_paraReturn()
{
    fakePPS->stop();

    iTestMode = 0;

    newTestPage->f_wcPage->txtMUYS->setText("0");

    nowtest=-1;
    newTestPage->btnAll->setVisible(false);
    isTested=false;
    bwFlag=-1;

    if (m_clnp->isOpen())
    {
        m_clnp->closeNetDev();//关闭网口
        m_clnp->recvThread->m_MUYSTime_Value = 0;
        newTestPage->btnTest->setText(tr("开始"));
    }

    timer->stop();
    udpTimer->stop();
    udp->setSt(false);

    udpOrder(0);
}
void MainWindow::f_paraOK()
{
    //
    m_Count_BigJC=0;//大角差
    m_clnp->recvThread->m_MUYSTime_Value = newTestPage->f_wcPage->txtMUYS->text().toInt();

    tDataProcess->init();
    tDataProcess->setBiJiaoCiShu(newTestPage->txtTestNum->text().toInt());

    if (newTestPage->f_wcPage->cboCTPT->currentIndex()==0)
    {
        tDataProcess->setTestType("I",newTestPage->f_wcPage->cboJD->currentText());
        myDB->setCTJD(newTestPage->f_wcPage->cboJD->currentText());
    }
    else if(newTestPage->f_wcPage->cboCTPT->currentIndex()==1)
    {
        tDataProcess->setTestType("U",newTestPage->f_wcPage->cboJD->currentText());
        myDB->setPTJD(newTestPage->f_wcPage->cboJD->currentText());
    }

    udp->harmonicOrder = 1;
    cappacket->harmonicOrder = 1;

    if(((newTestPage->f_wcPage->cboBzSelect->currentText()=="5A")&&(newTestPage->f_wcPage->cboBcSelect->currentText()=="1A"))||
      (((newTestPage->f_wcPage->cboBzSelect->currentText()=="1A")&&(newTestPage->f_wcPage->cboBcSelect->currentText()=="5A"))))
    {
       // QMessageBox::information(NULL,"测量参数选择","标准与被测参数不符合要求，不能进行测量！");
        myHelper::ShowMessageBoxInfo(tr("标准与被测参数不符合要求，不能进行测量！"));
        return;
    }
    initTest();

    QString xz=QString::number(newTestPage->f_wcPage->cboBzSelect->currentIndex()) + QString::number(newTestPage->f_wcPage->cboBcSelect->currentIndex());
    if (xz=="35")
        xz="25";
    if (xz=="34")
        xz="24";

    QSqlQuery tbWcbc=myDB->openWcxxforSql("select * from wcbc where type='"+xz +"'");
    if (tbWcbc.next())
    {
        bcdata[1]=tbWcbc.value(1).toDouble();
        jcdata[1]=tbWcbc.value(2).toDouble();
        bcdata[2]=tbWcbc.value(3).toDouble();
        jcdata[2]=tbWcbc.value(4).toDouble();
        bcdata[3]=tbWcbc.value(5).toDouble();
        jcdata[3]=tbWcbc.value(6).toDouble();
        bcdata[0]=tbWcbc.value(7).toDouble();
        jcdata[0]=tbWcbc.value(8).toDouble();
    }
    tbWcbc.clear();
    myDB->setHGQ_Channel(newTestPage->f_wcPage->cboBctd->currentIndex()+1);
    myDB->setTBFS(newTestPage->f_wcPage->cboTbfs->currentIndex());
    myDB->setBZXZ(newTestPage->f_wcPage->cboBzSelect->currentIndex());
    myDB->setBCXZ(newTestPage->f_wcPage->cboBcSelect->currentIndex());
    myDB->setBZXDY(newTestPage->f_wcPage->txtBzXdy->text());
    myDB->setBCXDY(newTestPage->f_wcPage->txtBcXdy->text());
    myDB->setBjcs(newTestPage->f_wcPage->txtTestNum->text().toInt());
    myDB->setSuanfa(newSysPage->cboSysSf->currentIndex());
  //  myDB->setCyys(newTestPage->txtYanshi->text().toInt());
    if(newTestPage->f_wcPage->cboCTPT->currentIndex()==0)
        myDB->setCTPT(0);
    else
        myDB->setCTPT(1);
    myDB->setEDYC(newTestPage->f_wcPage->txtEdyc->text());
    int icyfs=newTestPage->f_wcPage->cboCyfs->currentIndex();
    myDB->setCyfs(QString::number(icyfs));
    MAC=newTestPage->f_wcPage->txtMac->text();
    myDB->setMac(newTestPage->f_wcPage->txtMac->text());
    myDB->f_setXTCS();
    saveMuinfo();           //保存mac地址等信息

  //  QString sInfo="";
//    setparamsg();   //显示测量信息
    if (newTestPage->f_wcPage->txtTestNum->text().isEmpty())
        m_iAvgNum=0;
    else
        m_iAvgNum=newTestPage->f_wcPage->txtTestNum->text().toInt();
    m_iBiJiaoCiShu = m_iAvgNum;
  //  pagesWidget->setCurrentIndex(7);//测量界面统一为一个界面
    f_setTestText(0);
    if(newTestPage->f_wcPage->cboBzSelect->currentIndex()==0)
        bzTestXs=5;
    else if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==1)
        bzTestXs=1;
    else if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==2)
        bzTestXs=100;
    else if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==3)
        bzTestXs=57.73505;
    else
        bzTestXs=newTestPage->f_wcPage->txtBzXdy->text().toFloat();

    if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==0)
        bcTestXs=5;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==1)
        bcTestXs=1;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==2)
        bcTestXs=100;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==3)
        bcTestXs=57.73505;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==4)
        bcTestXs=newTestPage->f_wcPage->txtBcXdy->text().toFloat();
    else                //暂时为11585,如果为9-2则另外设置
        bcTestXs=11585;

    newTestPage->f_wcPage->btnTest->setText(tr("停止"));
    isTested=true;
    if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)
    {
        btnFlag=11;

        clfs=1;
        if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==5)
            //cappacket->setTestSelect(1);
         m_clnp->recvThread->setSuanFa(1);
        else
            //cappacket->setTestSelect(0);
         m_clnp->recvThread->setSuanFa(0);
   //     cappacket->setXieboNum(newTestPage->cboXbcs->currentText().toInt());

        if (newSysPage->cboSysSf->currentIndex()==1)
        {
       //     cappacket->setSuanFa(1);
            //cappacket->setSuanFa(2);
            m_clnp->recvThread->setSuanFa(2);
        }
        else
        {
           // cappacket->setSuanFa(0);
             m_clnp->recvThread->setSuanFa(0);
        }
    //    if (newSysPage->BLDG)
    //        cappacket->setSuanFa(2);


     //   cappacket->setSuanFa(0);
        /*
        int iTongDaoHao=newTestPage->cboBctd->currentText().toInt();
        int iChannel=iTongDaoHao;
        int imChannel = iChannel % 12;
        int icChannel = iChannel / 12;
        */
/*
        QModelIndex index;
        for(int i=1;i<13;i++)
        {
            index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
            if (imChannel==0)
                newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
            else
                newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
        }
        */
      //  newTestPage->tabTd->setVisible(true);
      //  newTestPage->rdoAlltd->setVisible(true);
     //   newTestPage->rdoCltd->setVisible(true);
       // newTestPage->f_wcPage->labSync->setText("");
    //    newTestPage->labSyncPng->setVisible(true);

        captimer->start(100);
    }
    else if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==6)            //Ft3
    {
        btnFlag=12;

        udp->setCTPT(newTestPage->f_wcPage->cboCTPT->currentIndex());

        clfs=2;
    }
    else
    {
        iTestMode=0;
        btnFlag=13;

        clfs=0;
   //     newTestPage->tabTd->setVisible(false);
   //     newTestPage->rdoAlltd->setVisible(false);
   //     newTestPage->rdoCltd->setVisible(false);
        //newTestPage->f_wcPage->labSync->setText("");
    //    newTestPage->labSyncPng->setVisible(false);
    }
    int ilen=newTestPage->f_wcPage->getStructLen();
    cUdpSend=(char*)malloc(ilen);
    newTestPage->f_wcPage->getsendUdp(cUdpSend,2);   //正常测量命令
    m_iFuwei=1;
    if (newSysPage->cboSysSf->currentIndex()==1)
        udp->setSuanFa(2);
    else
        udp->setSuanFa(0);
    udp->UdpSendByte(cUdpSend,ilen);
  //  udp->setFuZhi(bzTestXs);
 //   udp->setFuZhi_bc(bcTestXs);
    udpTimer->start(3000);
    udp->setRead(true);
   // newTestPage->f_wcPage->labSyncPng->setVisible(false);
    isSaved=true;
    nowXh="";
    preBFD="";

    qDebug()<<"settings is done! test start!";
}
void MainWindow::s_showMUYS()
{
    int muys = newTestPage->f_wcPage->txtMUYS->text().toInt();
    if(m_clnp->recvThread->m_MUYSTime_Value != 0)
        newTestPage->f_wcPage->txtMUYS->setText(QString::number(m_clnp->recvThread->m_MUYSTime_Value));
}

void MainWindow::f_jsWc()
{
    static double bzYxz_old = 0;
    static double bzXw_old = 0;

    // if we wanna support more data sequence, we need a array_buffer
    if ((netYouXiaoZhi != 0)&&(netXiangWei != 0))
    {
        qDebug()<<"sync num =" << tbsx;

        if (tbsx == 1)
        {
            f_ProcessData(netYouXiaoZhi*100,bzYxz,netXiangWei,bzXw);
        }
        else if(tbsx == 2)
        {
            if(bzYxz_old != 0 && bzXw_old != 0)
                f_ProcessData(m_clnp->recvThread->YouXiaoZhi()*100,bzYxz_old,m_clnp->recvThread->XiangWei(),bzXw_old);
        }
        else
        {
            f_ProcessData(m_clnp->recvThread->YouXiaoZhi()*100,bzYxz,m_clnp->recvThread->XiangWei(),bzXw);
        }

         f_showWcText();//f_wcPage->
    }

    bzYxz_old = bzYxz;
    bzXw_old = bzXw;

    bcYxz=m_dblYXZ_HGQ;
    netYouXiaoZhi=m_clnp->recvThread->YouXiaoZhi();
    netXiangWei=m_clnp->recvThread->XiangWei();
    //   update();
    udp->setIsOK(false);
}
void MainWindow::f_showWcText()//f_wcPage->
{
    //   labInfo->setText("d:"+QString::number(udp->getLost()));
    //   widgetInfo->show();
    //   showInfoTimer->start(2000);
       f_calculateAvg();
       newTestPage->f_wcPage->txtBzYxz->setText(infnan(QString::number(m_dblYXZ_JYY,'f',5)));
       newTestPage->f_wcPage->txtBzXw->setText(infnan(QString::number(m_dblXW_JYY,'f',2)));
       newTestPage->f_wcPage->txtBcYxz->setText(infnan(QString::number(m_dblYXZ_HGQ,'f',5)));
       newTestPage->f_wcPage->txtBcXw->setText(infnan(QString::number(m_dblXW_HGQ,'f',2)));
       newTestPage->f_wcPage->txtBc->setText(infnan(QString::number(m_dblBC,'f',4)));
       newTestPage->f_wcPage->txtJc->setText(infnan(QString::number(m_dblJC,'f',2)));
       newTestPage->f_wcPage->txtBFB->setText(infnan(QString::number(m_dblYXZ_JYY,'f',2)));
       emit f_sigTestEnd();
       m_BC[m_iTestNum]=m_dblBC;
       m_JC[m_iTestNum]=m_dblJC;

       m_iTestNum++;
       if (m_iTestNum>2)
       {
           m_iTestNum=0;
           double avgbc=0;
           double avgjc=0;
           double maxbc=0;
           double maxjc=0;
           double minbc=0;
           double minjc=0;
               if (m_BC[0]>m_BC[1])
               {
                   maxbc=m_BC[0];
                   minbc=m_BC[1];
               }
               else
               {
                   maxbc=m_BC[1];
                   minbc=m_BC[0];
               }
               if (m_JC[0]>m_JC[1])
               {
                   maxjc=m_JC[0];
                   minjc=m_JC[1];
               }
               else
               {
                   maxjc=m_JC[1];
                   minjc=m_JC[0];
               }
           if (maxbc<m_BC[2])
           {
               maxbc=m_BC[2];
           }
           if (maxjc<m_JC[2])
           {
               maxjc=m_JC[2];
           }
           if (minbc>m_BC[2])
           {
               minbc=m_BC[2];
           }
           if (minjc>m_JC[2])
           {
               minjc=m_JC[2];
           }
           for(int i=0;i<3;i++)
           {
               avgbc +=m_BC[i];
               avgjc +=m_JC[i];
           }
           avgbc /=3;
           avgjc /=3;
           newTestPage->f_wcPage->txtMaxBc->setText(infnan(QString::number(maxbc,'f',4)));
           newTestPage->f_wcPage->txtMaxJc->setText(infnan(QString::number(maxjc,'f',2)));
           newTestPage->f_wcPage->txtMinBc->setText(infnan(QString::number(minbc,'f',4)));
           newTestPage->f_wcPage->txtMinJc->setText(infnan(QString::number(minjc,'f',2)));
           newTestPage->f_wcPage->txtAvgBc->setText(infnan(QString::number(avgbc,'f',4)));
           newTestPage->f_wcPage->txtAvgJc->setText(infnan(QString::number(avgjc,'f',2)));
       }

       if(newTestPage->f_wcPage->cboBcSelect->currentIndex() == 6)
       {
           newTestPage->f_wcPage->txtMUYS->setText(QString::number( udp->getFt3Delay(),'f',1));
       }

       if (m_bIsConn)          //联机时上传误差数据;
       {
           QString s="1d:";
           s += newTestPage->f_wcPage->txtMUYS->text();
           s += ":";
           s += QString::number(m_dblYXZ_JYY,'f',6);
           s += ":";
           s += QString::number(m_dblXW_JYY,'f',2);
           s += ":";
           s += QString::number(m_dblYXZ_HGQ,'f',6);
           s += ":";
           s += QString::number(m_dblXW_HGQ,'f',2);
           s += ":";
           s += QString::number(m_dblYXZ_JYY,'f',2);
           s += ":";
           s += QString::number(m_dblBC,'f',4);
           s += ":";
           s += QString::number(m_dblJC,'f',2);
           tcpServer->TcpSend(s);

           // send part of the samples, for wave painting
           QString strBuff="1e";

           int NumOfSamples = udp->getMaxPoint();

           for(int i = 0; i < NumOfSamples; i++)
           {
               strBuff += ":" + QString::number(udp->m_tempBz[i],'f',4);
           }

           tcpServer->TcpSend(strBuff);

           strBuff = "1f";
           NumOfSamples = udp->getMaxPoint_Bc();

           if(newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5)
           {
               for(int i = 0; i < NumOfSamples; i++)
               {
                   strBuff += ":" + QString::number(udp->m_tempBc[i],'f',4);
               }
           }
           else
           {
               for(int i = 0; i < 12; i++)
               {
                   if(m_clnp->recvThread->GetChannelShow(i))
                   {
                       for(int j = 0; j < 80; j++)
                       {
                           strBuff += ":" + QString::number(m_clnp->recvThread->m_tempArray[i][j],'f',1);
                       }
                       break;
                   }
               }
           }

           tcpServer->TcpSend(strBuff);
       }
}
void MainWindow::f_slotTestEnd()
{
    double bfd,bc,jc;

    if (newTestPage->f_wcPage->cboSave->currentIndex()==0)   //如果是手动存储则退出
        return;

        wcbjWidget->setGeometry(380,180,250,200);
        bfd=newTestPage->f_wcPage->txtBFB->text().toDouble();
        bc=newTestPage->f_wcPage->txtBc->text().toDouble();
        jc=newTestPage->f_wcPage->txtJc->text().toDouble();

    bool isOK=tDataProcess->ProcessData(bfd);
    if (isOK)  //显示
    {
        yanshiNum++;
    //    if (yanshiNum<(newTestPage->txtYanshi->text().toInt()+1))
   //         return;
        tDataProcess->setCyFlag(true);
        wcbjWidget->setVisible(true);
        if (tDataProcess->getTestPointOver())
        {
            QString info="数据已存储！";
            tDataProcess->setTestPointOver(false);
            tDataProcess->setCyFlag(false);
            testnum=0;
            yanshiNum=0;
            modela->setRowCount(0);
            wcbjWidget->setVisible(false);
            saveWcdata();
         //   labInfo->setText(info);
            showInfoTimer->start(2000);
            if (tDataProcess->getTestOver())
            {
                info="全部测量完成！";
           //     labInfo->setText(info);
            }
            return;
        }
        testnum++;
        QStandardItem* item0=new QStandardItem();
        item0->setTextAlignment(Qt::AlignCenter);
        item0->setText(QString::number(testnum));
        QStandardItem* item1=new QStandardItem();
        item1->setTextAlignment(Qt::AlignCenter);
        item1->setText(QString::number(bc,'f',4));
        QStandardItem* item2=new QStandardItem();
        item2->setTextAlignment(Qt::AlignCenter);
        item2->setText(QString::number(jc,'f',2));
        QList<QStandardItem*> item;
        item << item0<< item1<< item2;
        modela->appendRow(item);
        tabWcbj->setModel(modela);
        int maxValue=tabWcbj->verticalScrollBar()->maximum();
        int nowValue=tabWcbj->verticalScrollBar()->value();
        if (nowValue<maxValue)
            tabWcbj->verticalScrollBar()->setSliderPosition(maxValue);
    }
}

bool MainWindow::f_ProcessData(double dblYXZ_HGQ, double dblYXZ_JYY, double dblXW_HGQ, double dblXW_JYY)
{
    dblYXZ_HGQ /=bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()];
    dblYXZ_JYY /=bzxs[newTestPage->f_wcPage->cboBzSelect->currentIndex()];
  //  qDebug()<<bzxs[newTestPage->cboBzSelect->currentIndex()];

//    if (bmstart)        //已同步
//    {
//        if (m_iAvgNum>=2)
//        {
//            m_dblAll_BzYxz[m_iTestTimes_BzYxz]=dblYXZ_JYY;
//            m_dblAll_BcYxz[m_iTestTimes_BcYxz]=dblYXZ_HGQ;
//           //// m_dblAll_BzXw[m_iTestTimes_BzXw]=dblXW_JYY;
//           //// m_dblAll_BcXw[m_iTestTimes_BcXw]=dblXW_HGQ;

//            m_iTestTimes_BzYxz++;
//            m_iTestTimes_BcYxz++;
//            m_iTestTimes_BzXw++;
//            m_iTestTimes_BcXw++;

//            double sysxs=myDB->sysXs.toDouble();
//           // double sysbc=myDB->sysBc.toDouble();
//         //   double sysjc=myDB->sysJc.toDouble();

//            double tempbzYxz=SZLBA(m_iTestTimes_BzYxz,m_dblAll_BzYxz);
//            double cz= (m_dblAll_BzYxz[m_iTestTimes_BzYxz-1] - tempbzYxz)/m_dblAll_BzYxz[m_iTestTimes_BzYxz-1]*100;
//            if (std::abs(cz)>sysxs)
//            {
//                for(int i=0;i<m_iTestTimes_BzYxz;i++)
//                {
//                    m_dblAll_BzYxz[i]=m_dblAll_BzYxz[m_iTestTimes_BzYxz-1];
//                }
//                tempbzYxz=m_dblAll_BzYxz[m_iTestTimes_BzYxz-1];
//                m_iTestTimes_BzYxz=1;
//            }
//            double tempbcYxz=SZLBA(m_iTestTimes_BcYxz,m_dblAll_BcYxz);
//            cz= (m_dblAll_BcYxz[m_iTestTimes_BcYxz-1] - tempbcYxz)/m_dblAll_BcYxz[m_iTestTimes_BcYxz-1]*100;
//            if (std::abs(cz)>sysxs)
//            {
//                for(int i=0;i<m_iTestTimes_BcYxz;i++)
//                {
//                    m_dblAll_BcYxz[i]=m_dblAll_BcYxz[m_iTestTimes_BcYxz-1];
//                }
//                tempbcYxz=m_dblAll_BcYxz[m_iTestTimes_BcYxz-1];
//                m_iTestTimes_BcYxz=1;
//            }
//            /*
//            double tempbzXw=SZLBA(m_iTestTimes_BzXw,m_dblAll_BzXw);
//            cz= m_dblAll_BzXw[m_iTestTimes_BzXw-1] - tempbzXw;
//            if (std::abs(cz)>sysjc)
//            {
//                for(int i=0;i<m_iTestTimes_BzXw;i++)
//                {
//                    m_dblAll_BzXw[i]=m_dblAll_BzXw[m_iTestTimes_BzXw-1];
//                }
//                tempbzXw=m_dblAll_BzXw[m_iTestTimes_BzXw-1];
//                m_iTestTimes_BzXw=1;
//            }
//            double tempbcXw=SZLBA(m_iTestTimes_BcXw,m_dblAll_BcXw);
//            cz= m_dblAll_BcXw[m_iTestTimes_BcXw-1] - tempbcXw;
//            if (std::abs(cz)>sysjc)
//            {
//                for(int i=0;i<m_iTestTimes_BcXw;i++)
//                {
//                    m_dblAll_BcXw[i]=m_dblAll_BcXw[m_iTestTimes_BcXw-1];
//                }
//                tempbcXw=m_dblAll_BcXw[m_iTestTimes_BcXw-1];
//                m_iTestTimes_BcXw=1;
//            }
//        */
//            dblYXZ_HGQ=tempbcYxz;
//            dblYXZ_JYY=tempbzYxz;
//        ////    dblXW_HGQ=tempbcXw;
//        ////    dblXW_JYY=tempbzXw;
//            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)  //数字量时补偿方法不同
//            {
//                dblXW_JYY += jcdata[0];
//                if (dblYXZ_JYY<2.0)
//                    dblXW_JYY +=jcdata[1];
//                else if (dblYXZ_JYY<10.0)
//                    dblXW_JYY +=jcdata[2];
//                else
//                    dblXW_JYY +=jcdata[3];
//            }

//            m_dblBC = (dblYXZ_HGQ - dblYXZ_JYY) / dblYXZ_JYY * 100;
//            m_dblJC = dblXW_HGQ - dblXW_JYY;
//            if (m_dblJC>180*60)
//                m_dblJC -= 360*60;
//            else if (m_dblJC<-180*60)
//                m_dblJC += 360*60;

//            //补偿=总体补偿+分段补偿
//            m_dblBC +=bcdata[0];
//            if (dblYXZ_JYY<2.0)
//                m_dblBC +=bcdata[1];
//            else if (dblYXZ_JYY<10.0)
//                m_dblBC +=bcdata[2];
//            else
//                m_dblBC +=bcdata[3];
//            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5)  //数字量时补偿方法不同
//            {
//                m_dblJC +=jcdata[0];
//                if (dblYXZ_JYY<2.0)
//                    m_dblJC +=jcdata[1];
//                else if (dblYXZ_JYY<10.0)
//                    m_dblJC +=jcdata[2];
//                else
//                    m_dblJC +=jcdata[3];
//            }
//            //合并单元延时信息+ 采样延时信息参与运算
//            m_dblJC = m_dblJC+ m_clnp->recvThread->m_MUYSTime_Value*1.08 -m_clnp->recvThread->m_YSTime_Value_t*1.08;
//            //m_dblJC = m_dblJC+ m_clnp->recvThread->m_YSTime_Value_t*1.08;
//            qDebug()<<"J:"<<m_clnp->recvThread->m_YSTime_Value_t;

//            m_dblAll_BC[m_iTestTimes_Bc]=m_dblBC;
//            m_dblAll_JC[m_iTestTimes_Jc]=m_dblJC;
//            m_iTestTimes_Bc++;
//            m_iTestTimes_Jc++;
//            m_dblBC=SZLB(m_iTestTimes_Bc,m_dblAll_BC);
//            m_dblJC=SZLB(m_iTestTimes_Jc,m_dblAll_JC);

//           if (m_iTestTimes_Bc>=m_iAvgNum)
//            {
//                for(int i=0;i<m_iTestTimes_Bc-1;i++)
//                {
//                    m_dblAll_BC[i]=m_dblAll_BC[i+1];
//                }
//                m_iTestTimes_Bc--;
//            }
//            if (m_iTestTimes_Jc>=m_iAvgNum)
//            {
//                for(int i=0;i<m_iTestTimes_Jc-1;i++)
//                {
//                    m_dblAll_JC[i]=m_dblAll_JC[i+1];
//                }
//                m_iTestTimes_Jc--;
//            }
//            if (m_iTestTimes_BzYxz>=10)//定为10次   m_iAvgNum
//            {
//                for(int i=0;i<m_iTestTimes_BzYxz-1;i++)
//                {
//                    m_dblAll_BzYxz[i]=m_dblAll_BzYxz[i+1];
//                }
//                m_iTestTimes_BzYxz--;
//            }
//            if (m_iTestTimes_BcYxz>=10)//定为10次   m_iAvgNum
//            {
//                for(int i=0;i<m_iTestTimes_BcYxz-1;i++)
//                {
//                    m_dblAll_BcYxz[i]=m_dblAll_BcYxz[i+1];
//                }
//                m_iTestTimes_BcYxz--;
//            }
//            if (m_iTestTimes_BzXw>=10)
//            {
//                for(int i=0;i<m_iTestTimes_BzXw-1;i++)
//                {
//                    m_dblAll_BzXw[i]=m_dblAll_BzXw[i+1];
//                }
//                m_iTestTimes_BzXw--;
//            }
//            if (m_iTestTimes_BcXw>=10)
//            {
//                for(int i=0;i<m_iTestTimes_BcXw-1;i++)
//                {
//                    m_dblAll_BcXw[i]=m_dblAll_BcXw[i+1];
//                }
//                m_iTestTimes_BcXw--;
//            }
//        }
//        else
//        {
//            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)  //数字量时补偿方法不同
//            {
//                dblXW_JYY += jcdata[0];
//                if (dblYXZ_JYY<2.0)
//                    dblXW_JYY +=jcdata[1];
//                else if (dblYXZ_JYY<10.0)
//                    dblXW_JYY +=jcdata[2];
//                else
//                    dblXW_JYY +=jcdata[3];
//            }
//            m_dblYXZ_HGQ=dblYXZ_HGQ;
//            m_dblYXZ_JYY=dblYXZ_JYY;
//            m_dblXW_HGQ=dblXW_HGQ;
//            m_dblXW_JYY=dblXW_JYY;
//            m_dblBC = (dblYXZ_HGQ - dblYXZ_JYY) / dblYXZ_JYY * 100;
//            m_dblJC = dblXW_HGQ - dblXW_JYY;
//            if (m_dblJC>180*60)
//                m_dblJC -= 360*60;
//            else if (m_dblJC<-180*60)
//                m_dblJC += 360*60;
//            //补偿=总体补偿+分段补偿
//            m_dblBC +=bcdata[0];
//            if (dblYXZ_JYY<2.0)
//                m_dblBC +=bcdata[1];
//            else if (dblYXZ_JYY<10.0)
//                m_dblBC +=bcdata[2];
//            else
//                m_dblBC +=bcdata[3];
//            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5)  //数字量时补偿方法不同
//            {
//                m_dblJC +=jcdata[0];
//                if (dblYXZ_JYY<2.0)
//                    m_dblJC +=jcdata[1];
//                else if (dblYXZ_JYY<10.0)
//                    m_dblJC +=jcdata[2];
//                else
//                    m_dblJC +=jcdata[3];
//            }
//            //合并单元延时信息+ 采样延时信息参与运算
//            m_dblJC = m_dblJC+ m_clnp->recvThread->m_MUYSTime_Value*1.08 -m_clnp->recvThread->m_YSTime_Value_t*1.08;
//            //m_dblJC = m_dblJC+ m_clnp->recvThread->m_YSTime_Value_t*1.08;
//            qDebug()<<"J:"<<m_clnp->recvThread->m_YSTime_Value_t;
//        }
//    }
    //else        //未同步
    {
        if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)  //数字量时补偿方法不同
        {
            dblXW_JYY += jcdata[0];
            if (dblYXZ_JYY<2.0)
                dblXW_JYY +=jcdata[1];
            else if (dblYXZ_JYY<10.0)
                dblXW_JYY +=jcdata[2];
            else
                dblXW_JYY +=jcdata[3];
        }
            m_dblBC = (dblYXZ_HGQ - dblYXZ_JYY) / dblYXZ_JYY * 100;
            m_dblJC = dblXW_HGQ - dblXW_JYY;
//            if (m_dblJC>180*60)
//                m_dblJC -= 360*60;
//            else if (m_dblJC<-180*60)
//                m_dblJC += 360*60;
            //补偿=总体补偿+分段补偿
            m_dblBC +=bcdata[0];
            if (dblYXZ_JYY<2.0)
                m_dblBC +=bcdata[1];
            else if (dblYXZ_JYY<10.0)
                m_dblBC +=bcdata[2];
            else
                m_dblBC +=bcdata[3];
            if (newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5)  //数字量时补偿方法不同
            {
                m_dblJC +=jcdata[0];
                if (dblYXZ_JYY<2.0)
                    m_dblJC +=jcdata[1];
                else if (dblYXZ_JYY<10.0)
                    m_dblJC +=jcdata[2];
                else
                    m_dblJC +=jcdata[3];
            }
        }
    double time2percent = 0;
    time2percent = 36*6*(udp->getPL())/10000;
    //合并单元延时信息+ 采样延时信息参与运算
    int muys = newTestPage->f_wcPage->txtMUYS->text().toInt();
        m_dblJC = m_dblJC+ muys*time2percent - m_clnp->recvThread->m_YSTime_Value_t*time2percent;
        //m_dblJC = m_dblJC+ m_clnp->recvThread->m_YSTime_Value_t*1.08;
        if(m_dblJC > 20000) m_dblJC -= 21600;

        //大数处理
        double old_jc = newTestPage->f_wcPage->txtJc->text().toDouble();
        double old_jc2 =std::abs(old_jc)* 2 ;//2倍 现有角差 绝对值
        double sub_jc = std::abs(m_dblJC-old_jc);

        if(sub_jc > old_jc2)//角差变化量记录
        {
            if(m_Count_BigJC > 1)
            {
                m_Count_BigJC = 0;//显示第三个大角差，同时置角差记录为0
            }
            else
            {
                m_dblJC = old_jc;//第一个、二个大数，暂时不显示，
                m_Count_BigJC++;//记录出现的大数个数
            }
        }
        else//正常角差：变比量小的，正常显示,同时置角差记录为0
        {
            m_Count_BigJC = 0;
        }
        //大数处理

        //qDebug()<<"J:"<<m_clnp->recvThread->m_YSTime_Value_t;
        m_dblYXZ_HGQ = dblYXZ_HGQ;
        m_dblYXZ_JYY = dblYXZ_JYY;

        m_dblXW_HGQ = dblXW_HGQ + muys*time2percent - m_clnp->recvThread->m_YSTime_Value_t*time2percent;

        if(m_dblXW_HGQ > 21600) m_dblXW_HGQ -= 21600;

        unSync_start_point = (muys - m_clnp->recvThread->m_YSTime_Value_t)/250;

        if(unSync_start_point < 0) unSync_start_point = 0;

        if(unSync_start_point > 80) unSync_start_point = 0;

        m_dblXW_JYY = dblXW_JYY;

        if(dblYXZ_HGQ == 0 || dblYXZ_JYY == 0)
        {
                return false;
        }else
        {
                m_iTestTimes++;
                return true;
        }
}

void MainWindow::f_settempbuff()
{
    //Sync(cappacket->getSync());
 //   sigBeginSync(cappacket->getSync());
    syncFlag=m_clnp->recvThread->getSync();
    bStart=false;
    m_MaxSZL=m_clnp->recvThread->getMaxShuZiLiang();
    /*
    for(int j=0;j<12;j++)
    {
        for(int i=0;i<iZHOUQI*200;i++)
        {
            tempbuff[j][i]=buf[j][i];
        }
    }
    */
    if (bwFlag==1)          //仅用于显示谐波，不显示图像
    {
        writeXBdata(0);
    }
    else
    {
        bStart=true;
    }

    memset(maxInChanel,0x00,sizeof(maxInChanel));

    qDebug()<<"paint on f_settempbuff";
    update();
}

void MainWindow::f_setTestText(int flag)
{
    if (flag==0)
    {
        newTestPage->f_wcPage->txtBzYxz->setText(tr("0.000000"));
        newTestPage->f_wcPage->txtBcYxz->setText(tr("0.000000"));
        newTestPage->f_wcPage->txtBzXw->setText(tr("0.00"));
        newTestPage->f_wcPage->txtBcXw->setText(tr("0.00"));
        newTestPage->f_wcPage->txtBFB->setText(tr("0.00"));
        newTestPage->f_wcPage->txtBc->setText(tr("0.0000"));
        newTestPage->f_wcPage->txtJc->setText(tr("0.00"));
        newTestPage->f_wcPage->txtMaxBc->setText(tr("0.0000"));
        newTestPage->f_wcPage->txtMaxJc->setText(tr("0.00"));
        newTestPage->f_wcPage->txtMinBc->setText(tr("0.0000"));
        newTestPage->f_wcPage->txtMinJc->setText(tr("0.00"));
        newTestPage->f_wcPage->txtAvgBc->setText(tr("0.0000"));
        newTestPage->f_wcPage->txtAvgJc->setText(tr("0.00"));
    }
    else
    {

        jsMaxMin();
    }
}
bool MainWindow::f_calculateAvg()
{
    if (!bmstart)
    {
        bmstart=true;
        double temp=std::abs(newTestPage->f_wcPage->txtJc->text().toDouble() - pWc);
        pWc=newTestPage->f_wcPage->txtJc->text().toDouble();
        if (temp<=5.0)
        {
            iStart++;
            if (iStart>=2)
            {
                bmstart=true;
                iStart=0;
            }
        }
        else
        {
        return false;
        }
   }
   if (m_iBiJiaoCiShu==0)
   {
       m_iTestTimes=0;
       return false;
   }
   /*
   if (m_iTestTimes==1)
   {
       m_dblMaxJC=m_dblJC;
       m_dblMinJC=m_dblJC;
       m_dblMaxBC=m_dblBC;
       m_dblMinBC=m_dblBC;
   }
*/
   m_dblAll_avgBC[m_iTestTimes_YouXiao]=newTestPage->f_wcPage->txtBc->text().toDouble();
   m_dblAll_avgJC[m_iTestTimes_YouXiao]=newTestPage->f_wcPage->txtJc->text().toDouble();

   m_iTestTimes_YouXiao++;		// 有效测量次数加1
   if(m_iTestTimes_YouXiao >= m_iBiJiaoCiShu)
   {
     //   double tempBc=SZLB(m_iTestTimes_YouXiao,m_dblAll_avgBC);
     //   double tempJc=SZLB(m_iTestTimes_YouXiao,m_dblAll_avgJC);
        for(int i=0;i<m_iBiJiaoCiShu-1;i++)
        {
            m_dblAll_avgBC[i]=m_dblAll_avgBC[i+1];
            m_dblAll_avgJC[i]=m_dblAll_avgJC[i+1];
        }
     //   m_iTestTimes_YouXiao--;
        m_iTestTimes_YouXiao=0;
        m_dblBC_Cnt=0;
        m_dblJC_Cnt=0;
    }
    return true;
}

void MainWindow::f_paintOnUdp(QWidget *w)
{
  //  qDebug()<<"ok";
  //  if (!udp->getIsOK())
  //      return;
    QPainter painter(w);
    QPoint beginPoint;
    QPoint endPoint;
    painter.translate(0,100);
    painter.drawLine(0,0,800,0);
    float dblWidth, dblHeight;
    dblWidth = (float)w->width();
    dblHeight = (float)w->height();

    //int iPoints_Bz = udp->getMaxPoint()* udp->getZhouQi();
    int iPoints_Bz = udp->getMaxPoint();
    int iPoints_Bc=0;
    double dblMaxBFB = 0.1;		// 最大百分表
    double dblMaxYXZ;
    double bzMaxYXZ,bcMaxYXZ,bcMaxFz,bzMaxFz;
    bzMaxYXZ=bzYxz * 1.414 / 100;       //标准的最大有效值
 //   double m_dblFuZhi;         //仅对标准有效

    bzMaxFz=(double)bzMax / bzTestXs;
    float dblScaling_Xbz,dblScaling_Xbc;
    dblScaling_Xbz= dblWidth / ((float)iPoints_Bz - 1);
    if (newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5) //非9-1或者9-2
    {
        bcMaxYXZ=bcYxz * 1.414 / 100;
        bcMaxFz=(double)bcMax / bcTestXs;        //被测的最大有效值
   //     m_dblFuZhi=bzTestXs;
        //iPoints_Bc = udp->getMaxPoint_Bc() * udp->getZhouQi_bc();
        iPoints_Bc = udp->getMaxPoint_Bc();
    }
    else if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)  //9-1或者9-2
    {
        bcMaxYXZ=m_clnp->recvThread->YouXiaoZhi()*1.414;
        bcMax=m_clnp->recvThread->getMaxShuZiLiang();
        bcTestXs=dblFuZhi_HGQ;
        bcMaxFz=(double)bcMax / bcTestXs;        //被测的最大有效值
 //       m_dblFuZhi=dblFuZhi_HGQ;
//        iPoints_Bc =m_clnp->recvThread->getPoint();
        iPoints_Bc=80;
    }
    if((iPoints_Bz==0)&&(iPoints_Bc==0))
        return;
/*
    newTestPage->txtBzYxz->setText(QString::number(m_dblYXZ_JYY,'f',6));
    newTestPage->txtBzXw->setText(QString::number(m_dblXW_JYY,'f',2));
    newTestPage->txtBcYxz->setText(QString::number(m_dblYXZ_HGQ,'f',6));
    newTestPage->txtBcXw->setText(QString::number(m_dblXW_HGQ,'f',2));
    newTestPage->txtBc->setText(QString::number(m_dblBC,'f',4));
    newTestPage->txtJc->setText(QString::number(m_dblJC,'f',2));
    newTestPage->txtBFB->setText(QString::number(m_dblYXZ_JYY*100,'f',2));
*/
    dblScaling_Xbc= dblWidth / ((float)iPoints_Bc - 1);
    if(bzMaxYXZ>bcMaxYXZ)
        dblMaxYXZ=bzMaxYXZ;
    else
        dblMaxYXZ=bcMaxYXZ;
    if(dblMaxBFB < dblMaxYXZ)
        dblMaxBFB = dblMaxYXZ;
    double dblFZ=0;
    if(bzMaxFz>bcMaxFz)
        dblFZ=bzMaxFz;
    else
        dblFZ=bcMaxFz;
    if(dblMaxBFB < dblFZ)
        dblMaxBFB = dblFZ;

 //   qDebug()<<bzMaxYXZ<<","<<bzMaxFz<<"  "<<bcMaxYXZ<<","<<bcMaxFz;

    dblMaxBFB += 0.05;

    QString MaxBFB=QString::number(bzMaxFz*bzTestXs,'f',2);
    newTestPage->maxBfb->setText(MaxBFB);
    float dblScaling_Ybz = dblHeight / ((float)bzTestXs * dblMaxBFB * 2);
    float dblScaling_Ybc = dblHeight / ((float)bcTestXs * dblMaxBFB * 2);

//标准图形
     //   int iZq=udp->getZhouQi();
     //   double dblBuChang = dblWidth / (iPoints_Bz);
        painter.setPen(Qt::white);
        for(int i = 0; i < iPoints_Bz-1; i++)
        {
/*
            beginPoint.setX(dblBuChang * (float)i);
            beginPoint.setY((dblHeight / 2) * (1 - udp->m_BzArray[i] / bzxs[newParaPage->cboBzSelect->currentIndex()]  / dblMaxBFB / bzTestXs)-100);
            endPoint.setX(dblBuChang * (float)i+1 );
            endPoint.setY((dblHeight / 2) * (1 - udp->m_BzArray[i+1] / bzxs[newParaPage->cboBzSelect->currentIndex()]  / dblMaxBFB / bzTestXs)-100);
            painter.drawLine(beginPoint, endPoint );
*/

            beginPoint.setX(dblScaling_Xbz * (float)i);
            beginPoint.setY(dblHeight / 2 - udp->m_tempBz[i] / bzxs[newTestPage->f_wcPage->cboBzSelect->currentIndex()] * dblScaling_Ybz-100);
            endPoint.setX(dblScaling_Xbz * (float)(i+1) );
            endPoint.setY(dblHeight / 2 - udp->m_tempBz[i+1] / bzxs[newTestPage->f_wcPage->cboBzSelect->currentIndex()] * dblScaling_Ybz-100);
            painter.drawLine( beginPoint, endPoint );
        //    qDebug()<<iPoints_Bz<<" "<<i<<" "<<udp->m_BzArray[i];

        }
 //       qDebug()<<"bz,"<<udp->m_BzArray[0]<<","<<udp->m_BzArray[1]<<","<<udp->m_BzArray[2];
//被测图形

        if(newTestPage->f_wcPage->cboBcSelect->currentIndex()!=5)  //非9-1或者9-2
        {
            painter.setPen(dataPen);
        //    double dblBuChang = dblWidth / (iPoints_Bc);
            for(int i = 0; i < iPoints_Bc-1; i++)
            {
/*
                beginPoint.setX(dblBuChang * (float)i);
                beginPoint.setY((dblHeight / 2) * (1 - udp->m_BcArray[i] / bcxs[newParaPage->cboBcSelect->currentIndex()]  / dblMaxBFB /bcTestXs)-100);
                endPoint.setX(dblBuChang * (float)i+1 );
                endPoint.setY((dblHeight / 2) * (1 - udp->m_BcArray[i+1] / bcxs[newParaPage->cboBcSelect->currentIndex()]  / dblMaxBFB /bcTestXs)-100);
                painter.drawLine(beginPoint, endPoint );

                */
                beginPoint.setX(dblScaling_Xbc * (float)i);
                beginPoint.setY(dblHeight / 2 - udp->m_tempBc[i] / bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                endPoint.setX(dblScaling_Xbc * (float)(i+1) );
                endPoint.setY(dblHeight / 2 - udp->m_tempBc[i+1] / bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                painter.drawLine( beginPoint, endPoint );
          //      qDebug()<<i<<" "<<udp->m_BcArray[i];
            }
            if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==6)  //ft3
            {
                int tdh=newTestPage->f_wcPage->cboBctd->currentText().toInt();
                unsigned short bzw=0;
                if (tdh<8)
                    bzw=(0x01<<(tdh+4)) & udp->etc_ft3.statusWord1;
                else
                    bzw=(0x01<<(tdh-8)) & udp->etc_ft3.statusWord2;
                if (bzw>0)
                {
                    painter.setPen(Qt::red);
                    painter.drawText(715,-80,"数据无效");
                }

                unsigned short wxFlag=0x01 & udp->etc_ft3.statusWord1;      //维修标志
                unsigned short jxFlag=(0x01<<1) & udp->etc_ft3.statusWord1; //检修标志test
                unsigned short hxFlag=(0x01<<2) & udp->etc_ft3.statusWord1; //唤醒标志
           //     unsigned short tbffFlag=(0x01<<3) & udp->etc_ft3.statusWord1;//同步方法
                unsigned short tbFlag=(0x01<<4) & udp->etc_ft3.statusWord1; //同步标志
                QString sinfo="";
                if (wxFlag>0)
                    sinfo +=tr("设备要求维修;");
                if (jxFlag>0)
                    sinfo +=tr("检修标志位:试验;");
                if (hxFlag>0)
                    sinfo +=tr("唤醒时间,全部数据无效;");
          //      labInfo->setText(sinfo);
                QString btl=tr("波特率:");
                btl +=QString::number((float)udp->etc_ft3.freq/10,'f',1);
//                if (tbFlag==0)
//                {
//                    painter.setPen(Qt::green);
//                    btl +=tr("M,已同步");
//                }
//                else
//                {
                    // btl +=tr("M,未同步");
                    painter.setPen(Qt::yellow);
                //}
                painter.drawText(1,-80,btl);
            }

        }
        else if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)  //9-1或者9-2
        {
        //    float dblScaling_X = dblWidth / ((float)iPoints - 1);
        //    float dblScaling_Y = dblHeight / ((float)m_dblFuZhi * dblMaxBFB * 2);
            for(int i = 0; i < 12; i++)
            {
                if(m_clnp->recvThread->GetChannelShow(i))
                {
                    painter.setPen(dataPen);
                    /*
                    switch(i)
                    {
                        case 0:
                            painter.setPen(QColor(0X00,0X80,0X00));
                            break;
                        case 1:
                            painter.setPen(QColor(0X80,0X80,0X00));
                            break;
                        case 2:
                            painter.setPen(QColor(0X00,0X00,0X80));
                            break;
                        case 3:
                            painter.setPen(QColor(0X80,0X00,0X80));
                            break;
                        case 4:
                            painter.setPen(QColor(0X00,0X80,0X80));
                            break;
                        case 5:
                            painter.setPen(QColor(0X80,0X80,0X80));
                            break;
                        case 6:
                            painter.setPen(QColor(0XC0,0XC0,0XC0));
                            break;
                        case 7:
                            painter.setPen(QColor(0XFF,0X00,0X00));
                            break;
                        case 8:
                            painter.setPen(QColor(0X00,0XFF,0X00));
                            break;
                        case 9:
                            painter.setPen(QColor(0XFF,0XFF,0X00));
                            break;
                        case 10:
                            painter.setPen(QColor(0X00,0X00,0XFF));
                            break;
                        case 11:
                            painter.setPen(QColor(0XFF,0X00,0XFF));
                            break;
                        default:
                            painter.setPen(Qt::red);
                            break;
                    }
                    */
                    volatile int jj = 0;

                    for(int j = 0; j < iPoints_Bc-1; j++)
                    {
                        jj = j + unSync_start_point + 1;

                        beginPoint.setX(dblScaling_Xbc * (float)j);     //tempbuff[i][j] m_PointArray

                        beginPoint.setY(dblHeight / 2 - m_clnp->recvThread->m_tempArray[i][jj] / bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                      //  beginPoint.setY(dblHeight / 2 - tempbuff[i][j] / bcxs[newParaPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                        endPoint.setX(dblScaling_Xbc * (float)(j+1) );
                        endPoint.setY(dblHeight / 2 - m_clnp->recvThread->m_tempArray[i][jj+1] / bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                     //   endPoint.setY(dblHeight / 2 - tempbuff[i][j+1] / bcxs[newParaPage->cboBcSelect->currentIndex()] * dblScaling_Ybc-100);
                        painter.drawLine( beginPoint, endPoint );
                  //      qDebug()<<i<<" "<<j<<" "<<cappacket->m_PointArray[i][j];
                    }
                    break;
                }
            }
            if(guiyue == GuiYue9_2)
            {
                if (syncFlag==0)
                {
                    painter.setPen(Qt::yellow);
                    painter.drawText(1,-80,"未同步");
                }
                else if (syncFlag==1)
                {
                    painter.setPen(Qt::green);
                    painter.drawText(1,-80,"已同步");
                }
            }
        }
//}
        QString pl= "Freq=";
        double dblpl=udp->getPL();
        pl += QString::number(dblpl,'f',4);
        pl += "Hz";
        painter.setPen(Qt::cyan);
        painter.drawText(700,145,pl);

        int xwj=std::abs(newTestPage->f_wcPage->txtJc->text().toDouble()/60);
        if ((dblpl>-35)&&(dblpl<65))
        {
            if ((newTestPage->f_wcPage->txtBzYxz->text().toDouble()!=0.0)&&(newTestPage->f_wcPage->txtBcYxz->text().toDouble()!=0))
            {
                QString jx="";
                if (xwj<60)
                    jx +=tr("极性:正");
                else if ((xwj>120)&&(xwj<240))
                    jx +=tr("极性:反");
                painter.setPen(Qt::darkCyan);
                painter.drawText(1,145,jx);
            }
            else
            {
                painter.drawText(1,145,"");
            }
        }

}
void MainWindow::f_setCSCS()
{
  //  int iTongDaoHao=newParaPage->cboBctd->currentText().toInt();
    int iCltd=newTestPage->f_wcPage->cboBctd->currentText().toInt();
    /*
    int iChannel=iCltd;

    int imChannel = iChannel % 12;
    int icChannel = iChannel / 12;
    for(int i=1;i<13;i++)
    {
        QModelIndex index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
        if (imChannel==0)
            newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
        else
            newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
    }

*/
  //  if (!isTested)
  //      return;
    guiyue=m_clnp->recvThread->GuiYueType();
    f_setparamsg();
    if(guiyue == GuiYue9_1)
    {
        dblFuZhi_HGQ = 11585;
    }
    else if(guiyue == GuiYue9_2)
    {
        if(newTestPage->f_wcPage->cboCTPT->currentIndex()==0)		// 如果是CT测量
            dblFuZhi_HGQ = myDB->edyc_dl.toInt() * 1000;
        else
        {
            if (newTestPage->f_wcPage->cboEdycDw->currentIndex()==0)
                dblFuZhi_HGQ = myDB->edyc_dy.toDouble() * 100000;
            else
                dblFuZhi_HGQ = myDB->edyc_dy.toDouble()/1.73205 * 100000;
        }
    }
    if (iTestMode==3)    //全帧解析
        m_clnp->recvThread->SetCapParamater(TestChannel_LuBo,m_zqgs,0,dblFuZhi_HGQ);//通道，周期,起始位,幅值
    else
        m_clnp->recvThread->SetCapParamater(iCltd-1,m_zqgs,0,dblFuZhi_HGQ);//通道，周期,起始位,幅值
    m_clnp->recvThread->setTestChannel(iCltd-1);
    f_tdSelect();
}

void MainWindow::f_tdSelect()
{
 /*   if (newTestPage->rdoCltd->isChecked())
    {
        */
        int iChannel=newTestPage->f_wcPage->cboBctd->currentText().toInt();
        iChannel %=12;

        if (iChannel==0)
            iChannel=12;

        for(int i=0;i<12;i++)
        {
            if (i==iChannel-1)
                m_clnp->recvThread->SetChannelShow(i,true);
            else
                m_clnp->recvThread->SetChannelShow(i,false);
        }
        /*
    }
    else if(newTestPage->rdoAlltd->isChecked())
    {
        for(int i=0;i<12;i++)
           cappacket->SetChannelShow(i,true);
    }
    */
}

void MainWindow::f_setparamsg()
{
 //   QString smsg="<h2><font size=3 color=red>同步方式:";
    QString smsg="非同步方式:";
 //   smsg+=newParaPage->cboTbfs->currentText()+";</font>";
    smsg+=newTestPage->cboTbfs->currentText();
  //  smsg+="<font size=3 color=white>标准:";
    smsg+=";标准:";
    if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==4)
        smsg+=newTestPage->f_wcPage->txtBzXdy->text()+ "V";
    else
        smsg+=newTestPage->f_wcPage->cboBzSelect->currentText();
 //   smsg+=";颜色:白色; </font>";
    smsg+=";颜色:白色";
   // smsg+="<font size=3 color=yellow>被测:";
    smsg+=";被测:";
    if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==4)
    {
        smsg+=newTestPage->f_wcPage->txtBcXdy->text()+ "V";
    }
    else
    {
        if(guiyue == GuiYue9_1)
            smsg+="光纤 61850-9-1";
        else if(guiyue == GuiYue9_2)
            smsg+="光纤 61850-9-2";
        else
            smsg+=newTestPage->f_wcPage->cboBcSelect->currentText();

    }
    if ((newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)||(newTestPage->f_wcPage->cboBcSelect->currentIndex()==6))
    {
        smsg+=";  被测通道: ";
        smsg+=QString::number(newTestPage->f_wcPage->cboBctd->currentIndex()+1);
        newTestPage->f_wcPage->labyxz->setText(tr("有效值(%)"));
        if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==6)
            smsg+=tr(",颜色:绿色;");
    }
    else
    {
        smsg+=tr(",颜色:绿色;");
        /*
        if (newParaPage->rdoGC->isChecked())
            smsg+=tr(" 算法名称：工程算法(直角坐标系)");
        else
            smsg+=tr(" 算法名称：理论算法(极坐标系)");
        */
        if (newTestPage->f_wcPage->cboBzSelect->currentIndex()<=1)
            newTestPage->f_wcPage->labyxz->setText(tr("有效值(A)"));
        else
            newTestPage->f_wcPage->labyxz->setText(tr("有效值(V)"));
    }
  //  smsg +="</font></h2>";
    newTestPage->labInfo->setText(smsg);
/*
    QString s =tr("单位:");
    if (newParaPage->cboBzSelect->currentIndex()<=1)
        s+="A";
    else
        s+="V";
*/
    QString s=tr("幅值");
    newTestPage->labDw->setText(s.split("", QString::SkipEmptyParts).join("\n"));
}

void MainWindow::f_slotShowList()
{
  //  pagesWidget->setCurrentIndex(6);
  //  btn1->setVisible(true);
  //  btn1->setEnabled(true);
  //  btn1->setText(tr("确定"));
 //   btn2->setVisible(false);
    newSclPage->labInfo->setText(tr(""));
    newSclPage->labTdh->setVisible(false);
    newSclPage->cboTdh->setVisible(false);
    newSclPage->setGeometry(490,310,530,300);
    newSclPage->show();
    newTestPage->f_wcPage->widgetWcTxt->setVisible(false);

    btnFlag=102;
    model=new QStandardItemModel(0,6);
    model->setHeaderData(0,Qt::Horizontal,tr("序号"));
    model->setHeaderData(1,Qt::Horizontal,tr("APPID"));
    model->setHeaderData(2,Qt::Horizontal,tr("MAC"));
    model->setHeaderData(3,Qt::Horizontal,tr("类型"));
    model->setHeaderData(4,Qt::Horizontal,tr("采样频率"));
    model->setHeaderData(5,Qt::Horizontal,tr("ASDU数目"));
    newSclPage->tabScl->setModel(model);
    newSclPage->tabScl->setColumnWidth(0,50);
    newSclPage->tabScl->setColumnWidth(1,60);
    newSclPage->tabScl->setColumnWidth(2,180);
    newSclPage->tabScl->setColumnWidth(3,75);
    newSclPage->tabScl->setColumnWidth(4,70);
    newSclPage->tabScl->setColumnWidth(5,75);
    showAllTimer->start(100);
}
void MainWindow::f_slotShowScl()
{
    newSclPage->labInfo->setText(tr(""));
    newSclPage->labTdh->setVisible(true);
    newSclPage->cboTdh->setVisible(true);
    newSclPage->cboTdh->clear();
    newSclPage->setGeometry(490,310,530,300);
   // newSclPage->setMaximumWidth(240);
    newSclPage->show();
    newTestPage->f_wcPage->widgetWcTxt->setVisible(false);

    btnFlag=101;
    QString fileName="";
    fileName= QFileDialog::getOpenFileName(this, tr("open file"), " ", tr("sclfile(*.scd *.cid *.icd)"));
    if (fileName=="")
    {
        qDebug()<<"打开配置文件失败!";
        return;
    }
    QFile file(fileName);
    if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
      //  ui->radioButton->setChecked(true);
        reader.clear();
        reader.read(&file);
        showAllMMS();
    }
    else
    {
        qDebug()<<"No file to read...";
    }
    file.close();
}
void MainWindow::f_paintOnLubo(QWidget *w)
{
  //  if (!cappacket->getIsOK())
  //      return;
  //  cappacket->StopCap(true);
    QPainter painter(w);
    QPoint beginPoint;
    QPoint endPoint;
    painter.translate(0,100);
    painter.drawLine(0,0,800,0);

    float dblWidth, dblHeight;
    dblWidth = (float)w->width();
    dblHeight = (float)w->height();
 //   int iPoints;		// 点数
    float dblScaling_X, dblScaling_Y;		// X轴和Y轴的缩放比例
    double dblMaxBFB = 0.1;		// 最大百分表
    double m_iShuZiLiangMax=0;
    m_iShuZiLiangMax=m_MaxSZL;
   // m_iShuZiLiangMax=cappacket->getMaxShuZiLiang();
    if (m_iShuZiLiangMax==0.0)
        return;
    double m_dblFuZhi=dblFuZhi_HGQ;
    double dblFZ=(double)m_iShuZiLiangMax / (double)m_dblFuZhi;
    if(dblMaxBFB < dblFZ)
        dblMaxBFB = dblFZ;
    dblMaxBFB += 0.05;

     if(m_iShuZiLiangMax != 0)
        dblScaling_Y = dblHeight / ((float)m_dblFuZhi * dblMaxBFB * 2);
    else
        dblScaling_Y = 0;
//    if (iTestMode==2)
//        m_dblShowPeriods=cappacket->ZhouQi();
    for(int i = 0; i < 12; i++)
    {
        bool doShow = m_clnp->recvThread->GetChannelShow(i);

        if( iTestMode == 3)
        {
            if(i == allChannelShow)
            {
                doShow = true;
            }
            else
            {
                doShow = false;
            }
        }

        if( doShow )
        {
            if (iTestMode == 3)
            {
                QPen greenPen;
                greenPen.setColor(Qt::green);
                greenPen.setWidth(3);

                painter.setPen(greenPen);
            }
            else
            {
                switch(i)
                {
                    case 0:
                            painter.setPen(QColor(0X00,0X80,0X00));
                            break;
                    case 1:
                            painter.setPen(QColor(0X80,0X80,0X00));
                            break;
                    case 2:
                            painter.setPen(QColor(0X00,0X00,0X80));
                            break;
                    case 3:
                            painter.setPen(QColor(0X80,0X00,0X80));
                            break;
                    case 4:
                            painter.setPen(QColor(0X00,0X80,0X80));
                            break;
                    case 5:
                            painter.setPen(QColor(0X80,0X80,0X80));
                            break;
                    case 6:
                            painter.setPen(QColor(0XC0,0XC0,0XC0));
                            break;
                    case 7:
                            painter.setPen(QColor(0XFF,0X00,0X00));
                            break;
                    case 8:
                            painter.setPen(QColor(0X00,0XFF,0X00));
                            break;
                    case 9:
                            painter.setPen(QColor(0XFF,0XFF,0X00));
                            break;
                    case 10:
                            painter.setPen(QColor(0X00,0X00,0XFF));
                            break;
                    case 11:
                            painter.setPen(QColor(0XFF,0X00,0XFF));
                            break;
                    default:
                            painter.setPen(Qt::red);
                            break;
                }
            }
            int iArrLen = m_dblShowPeriods * m_clnp->recvThread->SmpRate();

            dblScaling_X = dblWidth / ((float)iArrLen - 1);

            for(int j = 0; j < iArrLen-1; j++)
            {
                beginPoint.setX(dblScaling_X * (float)j);
                beginPoint.setY(dblHeight / 2 - m_clnp->recvThread->m_PointArray[i][m_iStartPoint+j]  / bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()] * dblScaling_Y-100);
                endPoint.setX(dblScaling_X * (float)(j+1) );
                endPoint.setY(dblHeight / 2 - m_clnp->recvThread->m_PointArray[i][m_iStartPoint+j+1]  / bcxs[newTestPage->f_wcPage->cboBcSelect->currentIndex()] * dblScaling_Y-100);
                painter.drawLine( beginPoint, endPoint );

                if( fabs(m_clnp->recvThread->m_PointArray[i][m_iStartPoint+j]) > maxInChanel[allChannelShow] )
                    maxInChanel[allChannelShow] = fabs(m_clnp->recvThread->m_PointArray[i][m_iStartPoint+j]);
            }
        }
    }
}

void MainWindow::parsePacket(const u_char *recvBuf, int recvLen)
{
    m_clnp->recvThread->CapNextPkt(recvBuf,recvLen);
}

void MainWindow::f_changeJD(QString type)
{
    QString sql;
    QSqlQuery tempjd;
    sql="select distinct testlevel from testdata where testtype='"+ type +"'";
    tempjd=myDB->openWcxxforSql(sql);
    newTestPage->f_wcPage->cboJD->clear();
    while (tempjd.next())
    {
        newTestPage->f_wcPage->cboJD->addItem(tempjd.value(0).toString());
    }
    tempjd.clear();
}

void MainWindow::f_Init_F_para()//LM ·ÇÍ¬²œ²âÁ¿£¬³õÊŒ»¯f_wcPage
{
    unSync_start_point = 0;

    //QString sNetPortDescription=NETDEV;
    m_clnp->openNetDev(etherPortName,&errBuf);
    tDataProcess->init();
    tDataProcess->setBiJiaoCiShu(newTestPage->txtTestNum->text().toInt());
    if (newTestPage->f_wcPage->cboCTPT->currentIndex()==0)
    {
        tDataProcess->setTestType("I",newTestPage->f_wcPage->cboJD->currentText());
        myDB->setCTJD(newTestPage->f_wcPage->cboJD->currentText());
    }
    else if(newTestPage->f_wcPage->cboCTPT->currentIndex()==1)
    {
        tDataProcess->setTestType("U",newTestPage->f_wcPage->cboJD->currentText());
        myDB->setPTJD(newTestPage->f_wcPage->cboJD->currentText());
    }


    if(((newTestPage->f_wcPage->cboBzSelect->currentText()=="5A")&&(newTestPage->f_wcPage->cboBcSelect->currentText()=="1A"))||
      (((newTestPage->f_wcPage->cboBzSelect->currentText()=="1A")&&(newTestPage->f_wcPage->cboBcSelect->currentText()=="5A"))))
    {
       // QMessageBox::information(NULL,"²âÁ¿²ÎÊýÑ¡Ôñ","±ê×ŒÓë±»²â²ÎÊý²»·ûºÏÒªÇó£¬²»ÄÜœøÐÐ²âÁ¿£¡");
        myHelper::ShowMessageBoxInfo(tr("±ê×ŒÓë±»²â²ÎÊý²»·ûºÏÒªÇó£¬²»ÄÜœøÐÐ²âÁ¿£¡"));
        return;
    }
    initTest();

    QString xz=QString::number(newTestPage->f_wcPage->cboBzSelect->currentIndex()) + QString::number(newTestPage->f_wcPage->cboBcSelect->currentIndex());
    if (xz=="35")
        xz="25";
    if (xz=="34")
        xz="24";

    QSqlQuery tbWcbc=myDB->openWcxxforSql("select * from wcbc where type='"+xz +"'");
    if (tbWcbc.next())
    {
        bcdata[1]=tbWcbc.value(1).toDouble();
        jcdata[1]=tbWcbc.value(2).toDouble();
        bcdata[2]=tbWcbc.value(3).toDouble();
        jcdata[2]=tbWcbc.value(4).toDouble();
        bcdata[3]=tbWcbc.value(5).toDouble();
        jcdata[3]=tbWcbc.value(6).toDouble();
        bcdata[0]=tbWcbc.value(7).toDouble();
        jcdata[0]=tbWcbc.value(8).toDouble();
    }
    tbWcbc.clear();
    myDB->setHGQ_Channel(newTestPage->f_wcPage->cboBctd->currentIndex()+1);
    myDB->setTBFS(newTestPage->f_wcPage->cboTbfs->currentIndex());
    myDB->setBZXZ(newTestPage->f_wcPage->cboBzSelect->currentIndex());
    myDB->setBCXZ(newTestPage->f_wcPage->cboBcSelect->currentIndex());
    myDB->setBZXDY(newTestPage->f_wcPage->txtBzXdy->text());
    myDB->setBCXDY(newTestPage->f_wcPage->txtBcXdy->text());
    myDB->setBjcs(newTestPage->f_wcPage->txtTestNum->text().toInt());
    myDB->setSuanfa(newSysPage->cboSysSf->currentIndex());
  //  myDB->setCyys(newTestPage->txtYanshi->text().toInt());
    if(newTestPage->f_wcPage->cboCTPT->currentIndex()==0)
        myDB->setCTPT(0);
    else
        myDB->setCTPT(1);
    myDB->setEDYC(newTestPage->f_wcPage->txtEdyc->text());
    int icyfs=newTestPage->f_wcPage->cboCyfs->currentIndex();
    myDB->setCyfs(QString::number(icyfs));
    MAC=newTestPage->f_wcPage->txtMac->text();
    myDB->setMac(newTestPage->f_wcPage->txtMac->text());
    myDB->f_setXTCS();
    saveMuinfo();           //±£ŽæmacµØÖ·µÈÐÅÏ¢

  //  QString sInfo="";
//    setparamsg();   //ÏÔÊŸ²âÁ¿ÐÅÏ¢
    if (newTestPage->f_wcPage->txtTestNum->text().isEmpty())
        m_iAvgNum=0;
    else
        m_iAvgNum=newTestPage->f_wcPage->txtTestNum->text().toInt();
    m_iBiJiaoCiShu = m_iAvgNum;
  //  pagesWidget->setCurrentIndex(7);//²âÁ¿œçÃæÍ³Ò»ÎªÒ»žöœçÃæ
    f_setTestText(0);
    if(newTestPage->f_wcPage->cboBzSelect->currentIndex()==0)
        bzTestXs=5;
    else if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==1)
        bzTestXs=1;
    else if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==2)
        bzTestXs=100;
    else if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==3)
        bzTestXs=57.73505;
    else
        bzTestXs=newTestPage->f_wcPage->txtBzXdy->text().toFloat();

    if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==0)
        bcTestXs=5;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==1)
        bcTestXs=1;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==2)
        bcTestXs=100;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==3)
        bcTestXs=57.73505;
    else if (newTestPage->f_wcPage->cboBcSelect->currentIndex()==4)
        bcTestXs=newTestPage->f_wcPage->txtBcXdy->text().toFloat();
    else                //ÔÝÊ±Îª11585,Èç¹ûÎª9-2ÔòÁíÍâÉèÖÃ
        bcTestXs=11585;

    //newTestPage->f_wcPage->btnTest->setText(tr("Í£Ö¹"));
    isTested=true;
    if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==5)
    {
        btnFlag=11;

        clfs=1;
//        if (newTestPage->f_wcPage->cboBzSelect->currentIndex()==5)
            //cappacket->setTestSelect(1);
        // m_clnp->recvThread->setSuanFa(1);
      //  else
            //cappacket->setTestSelect(0);
         //m_clnp->recvThread->setSuanFa(0);
   //     cappacket->setXieboNum(newTestPage->cboXbcs->currentText().toInt());

        if (newSysPage->cboSysSf->currentIndex()==1)
        {
       //     cappacket->setSuanFa(1);
            //cappacket->setSuanFa(2);
            //m_clnp->recvThread->setSuanFa(2);
        }
        else
        {
           // cappacket->setSuanFa(0);
//             m_clnp->recvThread->setSuanFa(0);
        }
    //    if (newSysPage->BLDG)
    //        cappacket->setSuanFa(2);


     //   cappacket->setSuanFa(0);
        /*//
        int iTongDaoHao=newTestPage->cboBctd->currentText().toInt();
        int iChannel=iTongDaoHao;
        int imChannel = iChannel % 12;
        int icChannel = iChannel / 12;
        */
/*
        QModelIndex index;
        for(int i=1;i<13;i++)
        {
            index=newTestPage->tabTd->model()->index(0,i,QModelIndex());
            if (imChannel==0)
                newTestPage->tabTd->model()->setData(index,QString::number((iChannel/12-1) *12+i));
            else
                newTestPage->tabTd->model()->setData(index,QString::number(icChannel*12+i));
        }
        */
      //  newTestPage->tabTd->setVisible(true);
      //  newTestPage->rdoAlltd->setVisible(true);
     //   newTestPage->rdoCltd->setVisible(true);
       // newTestPage->f_wcPage->labSync->setText("");
    //    newTestPage->labSyncPng->setVisible(true);

        //captimer->start(100);
    }
    else if(newTestPage->f_wcPage->cboBcSelect->currentIndex()==6)            //Ft3
    {
        btnFlag=12;

//        udp->setCTPT(newTestPage->f_wcPage->cboCTPT->currentIndex());

        clfs=2;
    }
    else
    {
        iTestMode=0;
        btnFlag=13;

        clfs=0;
   //     newTestPage->tabTd->setVisible(false);
   //     newTestPage->rdoAlltd->setVisible(false);
   //     newTestPage->rdoCltd->setVisible(false);
        //newTestPage->f_wcPage->labSync->setText("");
    //    newTestPage->labSyncPng->setVisible(false);
    }
    int ilen=newTestPage->f_wcPage->getStructLen();
    cUdpSend=(char*)malloc(ilen);
    //newTestPage->f_wcPage->getsendUdp(cUdpSend,2);   //Õý³£²âÁ¿ÃüÁî
    m_iFuwei=1;
//    if (newSysPage->cboSysSf->currentIndex()==1)
//        udp->setSuanFa(2);
//    else
//        udp->setSuanFa(0);
//    udp->UdpSendByte(cUdpSend,ilen);
//  //  udp->setFuZhi(bzTestXs);
// //   udp->setFuZhi_bc(bcTestXs);
//    udpTimer->start(3000);
//    udp->setRead(true);
   // newTestPage->f_wcPage->labSyncPng->setVisible(false);
    isSaved=true;
    nowXh="";
    preBFD="";

}

void MainWindow::loadPortConfig()
{
    QSettings settings("HKEY_CURRENT_USER\\Software\\sanwei",QSettings::NativeFormat);

    etherPortName = settings.value("port").toString();

    qDebug() <<"etherPortName:"<< etherPortName;

    settings.deleteLater();
}
